[LyX/master] Make cursor width depend on current font

Jean-Marc Lasgouttes lasgouttes at lyx.org
Tue Oct 13 15:10:43 UTC 2020


commit c516c86d190852b030d17125dd476c1891755c09
Author: Jean-Marc Lasgouttes <lasgouttes at lyx.org>
Date:   Thu Oct 1 14:24:21 2020 +0200

    Make cursor width depend on current font
    
    This makes the cursor more visible wrt current font.
    
    Moreover make the cursor width scalable by default.
---
 src/BufferView.cpp      |    6 ++----
 src/LyXRC.h             |    2 +-
 src/mathed/MathData.cpp |    8 +++++---
 src/mathed/MathRow.h    |    7 +++++--
 4 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/src/BufferView.cpp b/src/BufferView.cpp
index 88fe021..576bc67 100644
--- a/src/BufferView.cpp
+++ b/src/BufferView.cpp
@@ -3067,18 +3067,16 @@ void BufferView::caretPosAndDim(Point & p, Dimension & dim) const
 	Cursor const & cur = cursor();
 	if (cur.inMathed()) {
 		MathRow const & mrow = mathRow(&cur.cell());
-		dim.asc = mrow.caret_ascent;
-		dim.des = mrow.caret_descent;
+		dim = mrow.caret_dim;
 	} else {
 		Font const font = cur.real_current_font;
 		frontend::FontMetrics const & fm = theFontMetrics(font);
+		dim.wid = fm.lineWidth();
 		dim.asc = fm.maxAscent();
 		dim.des = fm.maxDescent();
 	}
 	if (lyxrc.cursor_width > 0)
 		dim.wid = lyxrc.cursor_width;
-	else
-		dim.wid = 1 + int((lyxrc.currentZoom + 50) / 200.0);
 
 	p = getPos(cur);
 	p.y_ -= dim.asc;
diff --git a/src/LyXRC.h b/src/LyXRC.h
index 3ebecb7..8950ea5 100644
--- a/src/LyXRC.h
+++ b/src/LyXRC.h
@@ -560,7 +560,7 @@ public:
 	ScrollWheelZoom scroll_wheel_zoom = SCROLL_WHEEL_ZOOM_CTRL;
 	// FIXME: should be caret_width
 	///
-	int cursor_width = 1;
+	int cursor_width = 0;
 	/// One of: yes, no, ask
 	std::string close_buffer_with_last_view = "yes";
 };
diff --git a/src/mathed/MathData.cpp b/src/mathed/MathData.cpp
index 868321b..39d5f80 100644
--- a/src/mathed/MathData.cpp
+++ b/src/mathed/MathData.cpp
@@ -295,10 +295,12 @@ void MathData::metrics(MetricsInfo & mi, Dimension & dim, bool tight) const
 
 	// This is one of the the few points where the drawing font is known,
 	// so that we can set the caret vertical dimensions.
-	mrow.caret_ascent = min(dim.asc, fm.maxAscent());
-	mrow.caret_descent = min(dim.des, fm.maxDescent());
+	mrow.caret_dim.asc = min(dim.asc, fm.maxAscent());
+	mrow.caret_dim.des = min(dim.des, fm.maxDescent());
+	mrow.caret_dim.wid = fm.lineWidth();
+
 	/// do the same for math cells linearized in the row
-	MathRow caret_row = MathRow(mrow.caret_ascent, mrow.caret_descent);
+	MathRow caret_row = MathRow(mrow.caret_dim);
 	for (auto const & e : mrow)
 		if (e.type == MathRow::BEGIN && e.ar)
 			bv->setMathRow(e.ar, caret_row);
diff --git a/src/mathed/MathRow.h b/src/mathed/MathRow.h
index 6d1a410..f2b0445 100644
--- a/src/mathed/MathRow.h
+++ b/src/mathed/MathRow.h
@@ -16,6 +16,7 @@
 #include "MathClass.h"
 
 #include "ColorCode.h"
+#include "Dimension.h"
 
 #include "support/docstring.h"
 
@@ -86,7 +87,9 @@ public:
 	};
 
 	///
-	MathRow(int asc = 0, int des = 0) : caret_ascent(asc), caret_descent(des) {};
+	MathRow() {}
+	///
+	MathRow(Dimension const & dim) : caret_dim(dim) {}
 	///
 	typedef std::vector<Element> Elements;
 	///
@@ -119,7 +122,7 @@ public:
 	int kerning(BufferView const *) const;
 
 	/// useful when the caret visits this cell
-	int caret_ascent, caret_descent;
+	Dimension caret_dim;
 
 
 private:


More information about the lyx-cvs mailing list