[LyX features/biginset] Avoid full metrics computation with Update:FitCursor

Jean-Marc Lasgouttes lasgouttes at lyx.org
Tue Apr 30 14:13:26 UTC 2024


commit be4e5dd43bf1563db832599b9e23c8800889db52
Author: Jean-Marc Lasgouttes <lasgouttes at lyx.org>
Date:   Tue Apr 30 15:02:16 2024 +0200

    Avoid full metrics computation with Update:FitCursor
    
    The handling of Update::FitCursor traditionnally recomputes all
    metrics once or twice. Now that updateMetrics(false) ensures that all
    paragraphs that require it have a metrics, we might as well use that.
    
    Take this occasion to move handling of Update::SinglePar earlier,
    before the check for Update::ForceDraw.
    
    (cherry picked from commit a4d9315bc49445e4419b3b59fd238a13c5f7be31)
---
 src/BufferView.cpp | 32 ++++++++++++++++++--------------
 1 file changed, 18 insertions(+), 14 deletions(-)

diff --git a/src/BufferView.cpp b/src/BufferView.cpp
index dd2259747d..de82559485 100644
--- a/src/BufferView.cpp
+++ b/src/BufferView.cpp
@@ -549,36 +549,40 @@ void BufferView::processUpdateFlags(Update::flags flags)
 		updateMetrics(true);
 		// metrics is done, full drawing is necessary now
 		flags = (flags & ~Update::Force) | Update::ForceDraw;
-	} else if (flags & Update::ForceDraw)
+	}
+	/* If a single paragraph update has been requested and we are not
+	 * already repainting all, check whether this update changes the
+	 * paragraph metrics. If it does, then compute all metrics (in
+	 * case the paragraph is in an inset)
+	 *
+	 * We handle this before FitCursor because the later will require
+	 * correct metrics at cursor position.
+	 */
+	else if ((flags & Update::SinglePar) && !(flags & Update::ForceDraw)) {
+		if (!singleParUpdate())
+			updateMetrics(true);
+	}
+	else if (flags & Update::ForceDraw)
 		// This will compute only the needed metrics and update positions.
 		updateMetrics(false);
 
-	// Detect whether we can only repaint a single paragraph (if we
-	// are not already redrawing all).
-	// We handle this before FitCursor because the later will require
-	// correct metrics at cursor position.
-	if (!(flags & Update::ForceDraw)
-			&& (flags & Update::SinglePar)
-			&& !singleParUpdate())
-		updateMetrics(true);
-
 	// Then make sure that the screen contains the cursor if needed
 	if (flags & Update::FitCursor) {
 		if (needsFitCursor()) {
 			// First try to make the selection start visible
 			// (which is just the cursor when there is no selection)
 			scrollToCursor(d->cursor_.selectionBegin(), SCROLL_VISIBLE);
-			// Metrics have to be recomputed (maybe again)
-			updateMetrics(true);
+			// Metrics have to be updated
+			updateMetrics(false);
 			// Is the cursor visible? (only useful if cursor is at end of selection)
 			if (needsFitCursor()) {
 				// then try to make cursor visible instead
 				scrollToCursor(d->cursor_, SCROLL_VISIBLE);
 				// Metrics have to be recomputed (maybe again)
-				updateMetrics(true);
+				updateMetrics(false);
 			}
 		}
-		flags = flags & ~Update::FitCursor;
+		flags = (flags & ~Update::FitCursor) | Update::ForceDraw;
 	}
 
 	// Add flags to the the update flags. These will be reset to None


More information about the lyx-cvs mailing list