emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/scroll-on-jump fddbdfdfe0 11/31: Fix error where the pixel


From: ELPA Syncer
Subject: [nongnu] elpa/scroll-on-jump fddbdfdfe0 11/31: Fix error where the pixel scroll was left a non-zero value
Date: Thu, 7 Jul 2022 12:03:12 -0400 (EDT)

branch: elpa/scroll-on-jump
commit fddbdfdfe05c08f846c8b990c521bfe95efbc577
Author: Campbell Barton <ideasman42@gmail.com>
Commit: Campbell Barton <ideasman42@gmail.com>

    Fix error where the pixel scroll was left a non-zero value
---
 scroll-on-jump.el | 57 +++++++++++++++++++++++++++++++++++--------------------
 1 file changed, 36 insertions(+), 21 deletions(-)

diff --git a/scroll-on-jump.el b/scroll-on-jump.el
index 5bf22eb27f..6d57efd3a3 100644
--- a/scroll-on-jump.el
+++ b/scroll-on-jump.el
@@ -111,20 +111,23 @@ Argument ALSO-MOVE-POINT When non-nil, move the POINT as 
well."
     ((< delta-px 0)
       (let*
         (
-          (scroll-px-prev (- char-height (window-vscroll nil t))) ;; flip.
-          (scroll-px-next (+ scroll-px-prev (- delta-px))) ;; flip.
+          (scroll-px-prev (window-vscroll nil t))
+          (scroll-px-next (+ scroll-px-prev delta-px))
           (lines (/ scroll-px-next char-height))
           (scroll-px (- scroll-px-next (* lines char-height)))
           (lines-remainder 0))
+
+        (when (< scroll-px 0)
+          (setq lines (1- lines))
+          (setq scroll-px (+ char-height scroll-px)))
+
         (unless (zerop lines)
-          ;; flip
-          (setq lines-remainder
-            (- (scroll-on-jump--scroll-by-lines window (- lines) 
also-move-point)))
+          (setq lines-remainder (- (scroll-on-jump--scroll-by-lines window 
lines also-move-point)))
           (unless (zerop lines-remainder)
-            (setq scroll-px char-height)))
-        (set-window-vscroll window (- char-height scroll-px) t)
+            (setq scroll-px 0)))
+        (set-window-vscroll window scroll-px t)
 
-        (cons (- lines-remainder) (- lines))))
+        (cons lines-remainder lines)))
     ((> delta-px 0)
       (let*
         (
@@ -206,7 +209,8 @@ Argument ALSO-MOVE-POINT When non-nil, move the POINT as 
well."
                 (setq step (- step (* dir (- lines-done-abs 
lines-scroll-abs)))))
 
               ;; Faster alternative to scroll.
-              (scroll-on-jump--scroll-by-lines-simple window step t)
+              (scroll-on-jump--scroll-by-lines-simple window step nil)
+              (forward-line step)
 
               (setq lines-scroll (- lines-scroll step)))
 
@@ -278,8 +282,7 @@ Argument ALSO-MOVE-POINT When non-nil, move the POINT as 
well."
                             (t
                               (* px-scroll-abs factor)))))
                       (px-remainder (- px-target px-done-abs)))
-                    ;; Step result, we must move at least one pixel.
-                    (* dir (max 1 (floor px-remainder))))))
+                    (* dir px-remainder))))
 
               ;; Check if this is the last step.
               (setq px-done-abs (+ px-done-abs (abs step)))
@@ -289,7 +292,12 @@ Argument ALSO-MOVE-POINT When non-nil, move the POINT as 
well."
               (pcase-let
                 (
                   (`(,_lines-remainder . ,lines-handled)
-                    (scroll-on-jump--scroll-by-pixels window char-height step 
t)))
+                    (scroll-on-jump--scroll-by-pixels window char-height step 
nil)))
+
+                ;; Forward lines separately since we might be at end of the 
buffer
+                ;; and we want to be able to scroll - even if the point has 
reached it's limit.
+                (forward-line lines-handled)
+
                 (setq lines-scroll (- lines-scroll lines-handled)))
 
               (setq px-scroll (- px-scroll step)))
@@ -298,15 +306,22 @@ Argument ALSO-MOVE-POINT When non-nil, move the POINT as 
well."
             (redisplay t))
           (setq is-early-exit nil))
 
-        ;; ;; Re-enable when editing logic.
-        (when (and (null is-early-exit) (not (zerop px-scroll)))
-          (set-window-vscroll window 0 t)
-          (error "Internal error, 'px-scroll' should be zero"))
-
-        ;; If we exit early because of input.
-        (when is-early-exit
-          (set-window-vscroll window 0 t)
-          (scroll-on-jump--scroll-by-lines-simple window lines-scroll nil)))
+        (cond
+          ;; If we exit early because of input.
+          (is-early-exit
+            ;; Early exit, reset pixel scroll and scroll lines.
+            (set-window-vscroll window 0 t)
+            (scroll-on-jump--scroll-by-lines-simple window lines-scroll nil))
+
+          ;; Sanity check, if this fails there is an issue with internal logic.
+          ((not (zerop px-scroll))
+            (set-window-vscroll window 0 t)
+            (error "Internal error, 'px-scroll' should be zero"))
+
+          ;; Also should never happen.
+          ((not (zerop (window-vscroll window t)))
+            (set-window-vscroll window 0 t)
+            (message "Warning, sub-pixel scroll left set!"))))
 
       ;; Non-animated scrolling (immediate).
       (scroll-on-jump--scroll-by-lines-simple window lines-scroll nil)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]