From: Po Lu Date: Sat, 27 Nov 2021 05:46:35 +0000 (+0800) Subject: Make `pixel-scroll-precision-scroll-up' slightly more robust X-Git-Tag: emacs-29.0.90~3649^2~28 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=141425ce3b8646d589f6a3aaf16d981821b32631;p=emacs.git Make `pixel-scroll-precision-scroll-up' slightly more robust * lisp/pixel-scroll.el (pixel-scroll-precision-scroll-up): Subtract from existing vscroll if feasible. --- diff --git a/lisp/pixel-scroll.el b/lisp/pixel-scroll.el index 131519a2585..84e1f66fa55 100644 --- a/lisp/pixel-scroll.el +++ b/lisp/pixel-scroll.el @@ -432,21 +432,31 @@ the height of the current window." (vertical-motion -1) (setq current-y (- current-y (line-pixel-height))))) (let ((current-vscroll (window-vscroll nil t))) - (setq delta (- delta current-vscroll)) - (set-window-vscroll nil 0 t)) - (while (> delta 0) - (let ((position (pixel-point-and-height-at-unseen-line))) - (set-window-start nil (car position) t) - (setq delta (- delta (cdr position))))) - (when (< delta 0) - (when-let* ((desired-pos (posn-at-x-y 0 (+ (- delta) - (window-tab-line-height) - (window-header-line-height)))) - (desired-start (posn-point desired-pos)) - (desired-vscroll (cdr (posn-object-x-y desired-pos)))) - (unless (eq (window-start) desired-start) - (set-window-start nil desired-start t)) - (set-window-vscroll nil desired-vscroll t)))) + (if (<= delta current-vscroll) + (set-window-vscroll nil (- current-vscroll delta) t) + (setq delta (- delta current-vscroll)) + (set-window-vscroll nil 0 t) + (while (> delta 0) + (let ((position (pixel-point-and-height-at-unseen-line))) + (unless (cdr position) + (signal 'beginning-of-buffer nil)) + (set-window-start nil (car position) t) + ;; If the line above is taller than the window height (i.e. there's + ;; a very tall image), keep point on it. + (when (> (cdr position) (window-text-height nil t)) + (let ((vs (window-vscroll nil t))) + (goto-char (car position)) + (set-window-vscroll nil vs t))) + (setq delta (- delta (cdr position))))) + (when (< delta 0) + (when-let* ((desired-pos (posn-at-x-y 0 (+ (- delta) + (window-tab-line-height) + (window-header-line-height)))) + (desired-start (posn-point desired-pos)) + (desired-vscroll (cdr (posn-object-x-y desired-pos)))) + (unless (eq (window-start) desired-start) + (set-window-start nil desired-start t)) + (set-window-vscroll nil desired-vscroll t)))))) ;; FIXME: This doesn't work when there's an image above the current ;; line that is taller than the window.