diff --git a/CHANGELOG.md b/CHANGELOG.md index 75eac766..eedad6e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,8 @@ The format is based on [Keep a Changelog]. canonical representation of a candidate has been removed ([#403]). ### Features +* Line spacing is taken into account when using a fixed window height + ([#424], [#432]). * The new option `selectrum-max-window-height` can now be used to configure the maximal display window height analogue to the built-in `max-mini-window-height`. The new option replaces the usage of the @@ -368,11 +370,13 @@ The format is based on [Keep a Changelog]. [#413]: https://github.com/raxod502/selectrum/pull/413 [#414]: https://github.com/raxod502/selectrum/pull/414 [#420]: https://github.com/raxod502/selectrum/issues/420 +[#424]: https://github.com/raxod502/selectrum/issues/424 [#425]: https://github.com/raxod502/selectrum/issues/425 [#421]: https://github.com/raxod502/selectrum/pull/421 [#427]: https://github.com/raxod502/selectrum/issues/427 [#430]: https://github.com/raxod502/selectrum/pull/430 [#431]: https://github.com/raxod502/selectrum/pull/431 +[#432]: https://github.com/raxod502/selectrum/pull/432 ## 3.0 (released 2020-10-20) ### Breaking changes diff --git a/selectrum.el b/selectrum.el index 3f0e32ba..c1fcaf81 100644 --- a/selectrum.el +++ b/selectrum.el @@ -1292,24 +1292,24 @@ window is supposed to be shown vertically." (and (window-at-side-p window 'bottom) (not (window-at-side-p window 'top)))) (set-window-text-height window 1))) - ((and (or (bound-and-true-p selectrum-fix-minibuffer-height) - selectrum-fix-vertical-window-height) - vertical) + ((and vertical selectrum-fix-vertical-window-height) (let* ((max (selectrum--max-window-height)) - (height (if selectrum-display-action - max - ;; Add one for prompt. - (1+ max)))) - (set-window-text-height window height))) + (lines (if selectrum-display-action + max + ;; Add one for prompt. + (1+ max))) + ;; Include possible line spacing. + (height (* lines (line-pixel-height)))) + (selectrum--set-window-height window height))) (t (when-let ((expand (selectrum--expand-window-for-content-p window))) (cond (selectrum-display-action - (selectrum--update-display-window-height window)) + (selectrum--fit-window-to-buffer window)) (t - (selectrum--update-minibuffer-height window))))))) + (selectrum--set-window-height window))))))) -(defun selectrum--update-display-window-height (window) - "Update window height of WINDOW. +(defun selectrum--fit-window-to-buffer (window) + "Fit window height to its buffer contents. Also works for frames if WINDOW is the root window of its frame." (let ((window-resize-pixelwise t) (window-size-fixed nil) @@ -1317,10 +1317,11 @@ Also works for frames if WINDOW is the root window of its frame." (fit-window-to-buffer-horizontally nil)) (fit-window-to-buffer window nil 1))) -(defun selectrum--update-minibuffer-height (window) - "Update window height of minibuffer WINDOW. -WINDOW will be updated to fit its content vertically." - (let ((dheight (cdr (window-text-pixel-size window))) +(defun selectrum--set-window-height (window &optional height) + "Set window height of WINDOW to HEIGHT pixel. +If HEIGHT is not given WINDOW will be updated to fit its content +vertically." + (let ((dheight (or height (cdr (window-text-pixel-size window)))) (wheight (window-pixel-height window)) (window-resize-pixelwise t)) (window-resize