[LyX/master] Simplify greatly Buffer::scroll/Up/Down methods

Jean-Marc Lasgouttes lasgouttes at lyx.org
Tue Sep 3 13:59:31 UTC 2024


commit 86d2313ce323fd20fadd63f103625e15704ae527
Author: Jean-Marc Lasgouttes <lasgouttes at lyx.org>
Date:   Tue Sep 3 15:55:34 2024 +0200

    Simplify greatly Buffer::scroll/Up/Down methods
    
    The code there that checks whether we scroll beyond the top/bottom of
    document is not needed anymore, this is handled later by
    BufferView::update(bool).
    
    Note that this methods may disappear with time.
    
    No change intended.
---
 src/BufferView.cpp | 41 ++---------------------------------------
 1 file changed, 2 insertions(+), 39 deletions(-)

diff --git a/src/BufferView.cpp b/src/BufferView.cpp
index 2a3a9c58c4..0985f6f7f6 100644
--- a/src/BufferView.cpp
+++ b/src/BufferView.cpp
@@ -2848,34 +2848,13 @@ int BufferView::minVisiblePart()
 
 int BufferView::scroll(int pixels)
 {
-	if (pixels > 0)
-		return scrollDown(pixels);
-	if (pixels < 0)
-		return scrollUp(-pixels);
-	return 0;
+	d->anchor_ypos_ -= pixels;
+	return -pixels;
 }
 
 
 int BufferView::scrollDown(int pixels)
 {
-	Text * text = &buffer_.text();
-	TextMetrics & tm = d->text_metrics_[text];
-	int const ymax = height_ + pixels;
-	while (true) {
-		pair<pit_type, ParagraphMetrics const *> last = tm.last();
-		int bottom_pos = last.second->bottom();
-		if (lyxrc.scroll_below_document)
-			bottom_pos += height_ - minVisiblePart();
-		if (last.first + 1 == int(text->paragraphs().size())) {
-			if (bottom_pos <= height_)
-				return 0;
-			pixels = min(pixels, bottom_pos - height_);
-			break;
-		}
-		if (bottom_pos > ymax)
-			break;
-		tm.newParMetricsDown();
-	}
 	d->anchor_ypos_ -= pixels;
 	return -pixels;
 }
@@ -2883,22 +2862,6 @@ int BufferView::scrollDown(int pixels)
 
 int BufferView::scrollUp(int pixels)
 {
-	Text * text = &buffer_.text();
-	TextMetrics & tm = d->text_metrics_[text];
-	int ymin = - pixels;
-	while (true) {
-		pair<pit_type, ParagraphMetrics const *> first = tm.first();
-		int top_pos = first.second->top();
-		if (first.first == 0) {
-			if (top_pos >= 0)
-				return 0;
-			pixels = min(pixels, - top_pos);
-			break;
-		}
-		if (top_pos < ymin)
-			break;
-		tm.newParMetricsUp();
-	}
 	d->anchor_ypos_ += pixels;
 	return pixels;
 }


More information about the lyx-cvs mailing list