From 8e500e509ba20a6f1e2f794211055893774cbdaf Mon Sep 17 00:00:00 2001 From: Vedang Manerikar Date: Sat, 23 Jul 2022 16:23:52 -0700 Subject: Fix: Handle nil return value from `image-scroll` functions *Note*: This is a temporary fix. What happened? When the `arg` to `image-scroll-up` is 0, the function disregards the argument (scrolling up 0 lines means not changing anything) and returns a `nil` value. This causes the equality check in this commit to fail (the check is to see if we have hit the top or bottom of the page, since in this case "moving the image" will do nothing and we will have to move the page). The current fix adds an explicit null check to ensure that we don't compare scroll positions. Unknowns: under what conditions is the argument to `pdf-view-scroll-up-or-next-page` 0? Things to do: Review the `= window-vscroll image-scroll` pattern all over the code-base and refactor it to deal with `arg = 0` problem. Fixes: #131 --- lisp/pdf-view.el | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/lisp/pdf-view.el b/lisp/pdf-view.el index 7f7e57d..0820e8f 100644 --- a/lisp/pdf-view.el +++ b/lisp/pdf-view.el @@ -705,12 +705,15 @@ next page only on typing SPC (ARG is nil)." (interactive "P") (if (or pdf-view-continuous (null arg)) (let ((hscroll (window-hscroll)) - (cur-page (pdf-view-current-page))) - (when (or (= (window-vscroll nil pdf-view-have-image-mode-pixel-vscroll) - (image-scroll-up arg)) - ;; Workaround rounding/off-by-one issues. - (memq pdf-view-display-size - '(fit-height fit-page))) + (cur-page (pdf-view-current-page)) + (win-scroll (window-vscroll nil pdf-view-have-image-mode-pixel-vscroll)) + (img-scroll (image-scroll-up arg))) + (when (or + ;; There is no next line for the image to scroll to + (and img-scroll (= win-scroll img-scroll)) + ;; Workaround rounding/off-by-one issues. + (memq pdf-view-display-size + '(fit-height fit-page))) (pdf-view-next-page) (when (/= cur-page (pdf-view-current-page)) (image-bob) @@ -727,12 +730,15 @@ to previous page only on typing DEL (ARG is nil)." (interactive "P") (if (or pdf-view-continuous (null arg)) (let ((hscroll (window-hscroll)) - (cur-page (pdf-view-current-page))) - (when (or (= (window-vscroll nil pdf-view-have-image-mode-pixel-vscroll) - (image-scroll-down arg)) - ;; Workaround rounding/off-by-one issues. - (memq pdf-view-display-size - '(fit-height fit-page))) + (cur-page (pdf-view-current-page)) + (win-scroll (window-vscroll nil pdf-view-have-image-mode-pixel-vscroll)) + (img-scroll (image-scroll-down arg))) + (when (or + ;; There is no previous line for the image to scroll to + (and img-scroll (= win-scroll img-scroll)) + ;; Workaround rounding/off-by-one issues. + (memq pdf-view-display-size + '(fit-height fit-page))) (pdf-view-previous-page) (when (/= cur-page (pdf-view-current-page)) (image-eob) -- cgit v1.0