Make selections vertically tighter.

Introduce a new Row::contents_dim(), which height is restricted to the
row contents and does not contain any extra vertical spacing.

Rely on this for painting selections: if the selection starts on row,
for example, the ascent of the contents dim is considered. If ot was
started above, then the full dim is used.

Fixes bug #3899.
This commit is contained in:
Jean-Marc Lasgouttes 2021-02-16 12:21:12 +01:00
parent 090e9a6c36
commit a7c1a39b5b
3 changed files with 14 additions and 2 deletions

View File

@ -210,6 +210,11 @@ public:
///
int descent() const { return dim_.des; }
///
Dimension const & contents_dim() const { return contents_dim_; }
///
Dimension & contents_dim() { return contents_dim_; }
/// The offset of the left-most cursor position on the row
int left_x() const;
/// The offset of the right-most cursor position on the row
@ -348,6 +353,8 @@ private:
bool flushed_;
/// Row dimension.
Dimension dim_;
/// Row contents dimension. Does not contain the space above/below row.
Dimension contents_dim_;
/// true when this row lives in a right-to-left paragraph
bool rtl_;
/// true when a changebar should be drawn in the margin

View File

@ -577,8 +577,10 @@ void RowPainter::paintSelection() const
if (!row_.selection())
return;
int const y1 = yo_ - row_.ascent();
int const y2 = y1 + row_.height();
int const y1 = yo_ - (row_.begin_margin_sel ? row_.ascent()
: row_.contents_dim().asc);
int const y2 = yo_ + (row_.end_margin_sel ? row_.descent()
: row_.contents_dim().des);
// draw the margins
if (row_.isRTL() ? row_.end_margin_sel : row_.begin_margin_sel)

View File

@ -1185,6 +1185,9 @@ void TextMetrics::setRowHeight(Row & row) const
row.dim().asc = maxasc;
row.dim().des = maxdes;
// This is useful for selections
row.contents_dim() = row.dim();
}