]> git.lyx.org Git - features.git/commitdiff
Fine tune the scroll offset setting code
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Sat, 26 Jul 2014 14:25:56 +0000 (16:25 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 7 Jan 2015 21:55:11 +0000 (22:55 +0100)
The new code should feel a bit more natural. It avoids explicit pixel values for the margins and does not scroll in some cases where it is not necessary.

src/BufferView.cpp

index 4bd1c12e77d57f4e87a4774d0310a7bb77feef04..e4e2a83b4f2efa57ee5228c92c016e3e4a596975 100644 (file)
@@ -35,6 +35,7 @@
 #include "Language.h"
 #include "LaTeXFeatures.h"
 #include "LayoutFile.h"
+#include "Length.h"
 #include "Lexer.h"
 #include "LyX.h"
 #include "LyXAction.h"
@@ -2937,20 +2938,17 @@ void BufferView::checkCursorScrollOffset(PainterInfo & pi)
 
        // Horizontal scroll offset of the cursor row in pixels
        int offset = d->horiz_scroll_offset_;
-       int const MARGIN = 10;
+       int const MARGIN = Length(2, Length::EM).inPixels(workWidth());
        if (cur_x < offset + MARGIN) {
                // scroll right
                offset = cur_x - MARGIN;
        } else if (cur_x > offset + workWidth() - MARGIN) {
                // scroll left
                offset = cur_x - workWidth() + MARGIN;
-       } else if(offset > 0
-                 && row.width() - offset < workWidth()){
-               offset = row.width() - workWidth();
        }
 
-       if (offset != d->horiz_scroll_offset_)
-               LYXERR0("Offset is now " << offset);
+       if (offset < 0 || row.width() <= workWidth())
+               offset = 0;
 
        if (d->update_strategy_ == NoScreenUpdate
            && (offset != d->horiz_scroll_offset_