justbur / emacs-which-key

Emacs package that displays available keybindings in popup
GNU General Public License v3.0
1.73k stars 87 forks source link

Restore window scroll after popup close #361

Open 45mg opened 6 months ago

45mg commented 6 months ago

Currently, if displaying the popup would hide point, the window is scrolled to prevent this; but it is not scrolled back when the popup closes. This can be disorienting when the popup is tall, as the scroll changes by a large amount.

The solution is to store the scroll position of the selected window before showing the popup, and restore it after closing it.

https://github.com/justbur/emacs-which-key/pull/321 added an option to do the same thing, but only for the side-window popup type, and using set-window-configuration which is dangerous as discussed there. This solution should work for any popup function.

I didn't remove/deprecate the option introduced in #321, as users may have come to rely on side-effects from set-window-configuration (but mostly because it would put me over 15 lines 🙂).