[LyX/master] Make selections vertically tighter.
Jean-Marc Lasgouttes
lasgouttes at lyx.org
Tue Feb 16 11:26:09 UTC 2021
commit a7c1a39b5b35102da0fe508d4a13c88827f465cd
Author: Jean-Marc Lasgouttes <lasgouttes at lyx.org>
Date: Tue Feb 16 12:21:12 2021 +0100
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.
---
src/Row.h | 7 +++++++
src/RowPainter.cpp | 6 ++++--
src/TextMetrics.cpp | 3 +++
3 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/src/Row.h b/src/Row.h
index d210174..b54a233 100644
--- a/src/Row.h
+++ b/src/Row.h
@@ -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
diff --git a/src/RowPainter.cpp b/src/RowPainter.cpp
index 99393ca..309c0a4 100644
--- a/src/RowPainter.cpp
+++ b/src/RowPainter.cpp
@@ -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)
diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp
index 3154f0d..57956bd 100644
--- a/src/TextMetrics.cpp
+++ b/src/TextMetrics.cpp
@@ -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();
}
More information about the lyx-cvs
mailing list