]> git.lyx.org Git - lyx.git/commitdiff
Fix bug #6141: Scrolling error with insets at top of file.
authorVincent van Ravesteijn <vfr@lyx.org>
Mon, 26 Apr 2010 14:57:27 +0000 (14:57 +0000)
committerVincent van Ravesteijn <vfr@lyx.org>
Mon, 26 Apr 2010 14:57:27 +0000 (14:57 +0000)
Fix the regression introduced in r28397 while fixing bug #5573.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@34296 a592a061-630c-0410-9148-cb99ea01b6c8

src/BufferView.cpp

index 8ce25ec07f46a96f0a9be872445851e6af39185d..3aa1854d1fd9cdde12a3f9cefbca6fc1a5e73e7e 100644 (file)
@@ -874,10 +874,22 @@ bool BufferView::scrollToCursor(DocIterator const & dit, bool recenter)
                int scrolled = 0;
                if (recenter)
                        scrolled = scroll(ypos - height_/2);
+
+               // If the top part of the row falls of the screen, we scroll
+               // up to align the top of the row with the top of the screen.
                else if (ypos - row_dim.ascent() < 0)
-                       scrolled = scrollUp(- ypos + row_dim.ascent());
-               else if (ypos + row_dim.descent() > height_)
-                       scrolled = scrollDown(ypos - height_ + defaultRowHeight() ); 
+                       scrolled = scrollUp(-ypos + row_dim.ascent());
+
+               // If the bottom of the row falls of the screen, we scroll down.
+               // However, we have to be careful not to scroll that much that
+               // the top falls of the screen.
+               else if (ypos + row_dim.descent() > height_) {
+                       int ynew = height_ - row_dim.descent();
+                       if (ynew < row_dim.ascent())
+                               ynew = row_dim.ascent();
+                       int const scroll = ypos - ynew;
+                       scrolled = scrollDown(scroll);
+               }
 
                // else, nothing to do, the cursor is already visible so we just return.
                return scrolled != 0;