diff --git a/which-key.el b/which-key.el index d68942c..c11a36f 100644 --- a/which-key.el +++ b/which-key.el @@ -663,6 +663,9 @@ to a non-nil value for the execution of a command. Like this (defvar which-key--frame nil "Internal: Holds reference to which-key frame. Used when `which-key-popup-type' is frame.") +(defvar which-key--scroll-pos-table (make-hash-table :test 'equal) + "Internal: Holds initial scroll positions of windows +in which the which-key popup is showing.") (defvar which-key--echo-keystrokes-backup nil "Internal: Backup the initial value of `echo-keystrokes'.") (defvar which-key--prefix-help-cmd-backup nil @@ -1132,7 +1135,12 @@ total height." (when (and which-key-idle-secondary-delay which-key--secondary-timer-active) (which-key--start-timer)) (which-key--lighter-restore) - (which-key--hide-popup-ignore-command))) + (which-key--hide-popup-ignore-command) + ;; restore scroll position if saved earlier by `which-key--show-popup' + (let ((top-pos (gethash (selected-window) which-key--scroll-pos-table))) + (when top-pos + (scroll-down (count-screen-lines (window-start) top-pos)) + (remhash (selected-window) which-key--scroll-pos-table))))) (defun which-key--hide-popup-ignore-command () "Version of `which-key--hide-popup' without the check of @@ -1179,6 +1187,8 @@ buffer text to be displayed in the popup. Return nil if no window is shown, or if there is no need to start the closing timer." (when (and (> (car act-popup-dim) 0) (> (cdr act-popup-dim) 0)) + ;; save pos at top of this window + (puthash (selected-window) (window-start) which-key--scroll-pos-table) (cl-case which-key-popup-type ;; Not called for minibuffer ;; (minibuffer (which-key--show-buffer-minibuffer act-popup-dim))