From 6570eb09723a515baab475146bf5071bffba4b87 Mon Sep 17 00:00:00 2001 From: Clemens Radermacher Date: Sun, 2 Aug 2020 13:28:03 +0200 Subject: [PATCH 01/10] Don't allow line-spacing in minibuffer --- selectrum.el | 3 +++ 1 file changed, 3 insertions(+) diff --git a/selectrum.el b/selectrum.el index 14d6e890..41277a6b 100644 --- a/selectrum.el +++ b/selectrum.el @@ -958,6 +958,9 @@ CANDIDATES is the list of strings that was passed to `selectrum-read'. DEFAULT-CANDIDATE, if provided, is added to the list and sorted first. INITIAL-INPUT, if provided, is inserted into the user input area to start with." + ;; Avoid wrong minibuffer height. Minibuffer height is currently + ;; determined by amount of lines and not actual display height. + (setq-local line-spacing nil) (add-hook 'minibuffer-exit-hook #'selectrum--minibuffer-exit-hook nil 'local) (setq-local selectrum--init-p t) From 1ce6fba20f2d2ce986e8d24319968c317a5fb693 Mon Sep 17 00:00:00 2001 From: Clemens Radermacher Date: Sun, 2 Aug 2020 13:34:29 +0200 Subject: [PATCH 02/10] Update changelog --- CHANGELOG.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fcbb9087..c3633c69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,7 +49,7 @@ The format is based on [Keep a Changelog]. visible when it can be submitted (similar to the effect of `minibuffer-electric-default-mode`). * The default candidate shown in the prompt message is now displayed - with the face `selectrum-current-candidate` when it is selected. + with the face `selectrum-current-candidate` when it is selected.51 * Now that Selectrum always shows the default candidate when it can be submitted, it now attempts to remove the default candidate from prompt messages that already contain it. This decreases @@ -67,7 +67,8 @@ The format is based on [Keep a Changelog]. assumed that the minibuffer only contains user input would be likely to fail ([#124]). This also means inside the minibuffer `minibuffer-contents` now returns only the current input as expected - ([#116], [#133]). + ([#116], [#133]). In order to avoid wrong minibuffer heights + `line-spacing` got disabled for Selectrum sessions ([#151], [#154]). * Multiline candidates are now merged into a single truncated line so there is no gradual scrolling effect anymore when going through the candidate list. The first matched line is shown in front of the @@ -112,6 +113,8 @@ The format is based on [Keep a Changelog]. [#133]: https://github.com/raxod502/selectrum/pull/133 [#138]: https://github.com/raxod502/selectrum/pull/138 [#140]: https://github.com/raxod502/selectrum/pull/140 +[#151]: https://github.com/raxod502/selectrum/issues/151 +[#154]: https://github.com/raxod502/selectrum/pull/154 ## 2.0 (released 2020-07-18) ### Breaking changes From a032cac63eb8b5e02d4beaec0750de4c1ddc148c Mon Sep 17 00:00:00 2001 From: Clemens Radermacher Date: Sun, 2 Aug 2020 15:17:42 +0200 Subject: [PATCH 03/10] Determine actual text height to set window height --- CHANGELOG.md | 11 ++++++++--- selectrum.el | 30 ++++++++++++++++++++---------- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c3633c69..eb91716c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,7 +49,7 @@ The format is based on [Keep a Changelog]. visible when it can be submitted (similar to the effect of `minibuffer-electric-default-mode`). * The default candidate shown in the prompt message is now displayed - with the face `selectrum-current-candidate` when it is selected.51 + with the face `selectrum-current-candidate` when it is selected. * Now that Selectrum always shows the default candidate when it can be submitted, it now attempts to remove the default candidate from prompt messages that already contain it. This decreases @@ -67,14 +67,18 @@ The format is based on [Keep a Changelog]. assumed that the minibuffer only contains user input would be likely to fail ([#124]). This also means inside the minibuffer `minibuffer-contents` now returns only the current input as expected - ([#116], [#133]). In order to avoid wrong minibuffer heights - `line-spacing` got disabled for Selectrum sessions ([#151], [#154]). + ([#116], [#133]). * Multiline candidates are now merged into a single truncated line so there is no gradual scrolling effect anymore when going through the candidate list. The first matched line is shown in front of the merged lines ([#133]). ### Bugs fixed +* The mininbuffer height is now determined by the actual height of + displayed candidates. Previously the height could be off for + candidates containing unicode characters or other means which + changed the display height such as `line-spacing` ([#146], [#151], + [#154]). * Incremental history search via `isearch` wasn't working which has been fixed ([#124], [#133]). * Empty string completion candidates are now ignored like in the @@ -113,6 +117,7 @@ The format is based on [Keep a Changelog]. [#133]: https://github.com/raxod502/selectrum/pull/133 [#138]: https://github.com/raxod502/selectrum/pull/138 [#140]: https://github.com/raxod502/selectrum/pull/140 +[#146]: https://github.com/raxod502/selectrum/issues/146 [#151]: https://github.com/raxod502/selectrum/issues/151 [#154]: https://github.com/raxod502/selectrum/pull/154 diff --git a/selectrum.el b/selectrum.el index 41277a6b..2d894d0d 100644 --- a/selectrum.el +++ b/selectrum.el @@ -737,11 +737,6 @@ PRED defaults to `minibuffer-completion-predicate'." (setq displayed-candidates (seq-take displayed-candidates selectrum-num-candidates-displayed)) - (let ((n (1+ (if selectrum-fix-minibuffer-height - selectrum-num-candidates-displayed - (max (1- (window-height)) ; grow only - (length displayed-candidates)))))) - (setf (window-height) n)) (let ((text (selectrum--candidates-display-string displayed-candidates input @@ -788,6 +783,7 @@ PRED defaults to `minibuffer-completion-predicate'." (setq text (concat (or default " ") text)) (put-text-property 0 1 'cursor t text) (overlay-put selectrum--candidates-overlay 'after-string text))) + (selectrum--update-minibuffer-height) (setq selectrum--end-of-input-marker (set-marker (make-marker) bound)) (set-marker-insertion-type selectrum--end-of-input-marker t) (selectrum--fix-set-minibuffer-message) @@ -795,6 +791,22 @@ PRED defaults to `minibuffer-completion-predicate'." (setq deactivate-mark nil)) (setq-local selectrum--init-p nil))) +(defun selectrum--update-minibuffer-height () + "Set minibuffer height for candidates display." + (let ((n (1+ selectrum-num-candidates-displayed)) + (win (active-minibuffer-window))) + ;; Set min initial height. + (when (and selectrum-fix-minibuffer-height + selectrum--init-p) + (with-selected-window win + (setf (window-height) n))) + (let ((dheight (cdr (window-text-pixel-size win))) + (wheight (window-pixel-height win))) + ;; Grow if needed. + (when (> dheight wheight) + (window-resize + win (- dheight wheight) nil nil 'pixelwise))))) + (defun selectrum--first-lines (candidates) "Return list of single line CANDIDATES. Multiline canidates are merged into a single line." @@ -958,14 +970,12 @@ CANDIDATES is the list of strings that was passed to `selectrum-read'. DEFAULT-CANDIDATE, if provided, is added to the list and sorted first. INITIAL-INPUT, if provided, is inserted into the user input area to start with." - ;; Avoid wrong minibuffer height. Minibuffer height is currently - ;; determined by amount of lines and not actual display height. - (setq-local line-spacing nil) (add-hook 'minibuffer-exit-hook #'selectrum--minibuffer-exit-hook nil 'local) (setq-local selectrum--init-p t) - (setq selectrum--candidates-overlay - (make-overlay (point) (point) nil 'front-advance 'rear-advance)) + (unless selectrum--candidates-overlay + (setq selectrum--candidates-overlay + (make-overlay (point) (point) nil 'front-advance 'rear-advance))) (setq selectrum--start-of-input-marker (point-marker)) (if selectrum--repeat (insert selectrum--previous-input-string) From a073e77372e4055306a7d1c74160038f70d00e14 Mon Sep 17 00:00:00 2001 From: Clemens Radermacher Date: Mon, 3 Aug 2020 18:05:46 +0200 Subject: [PATCH 04/10] Improve height change behaviour --- selectrum.el | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/selectrum.el b/selectrum.el index 2d894d0d..3b2e9c11 100644 --- a/selectrum.el +++ b/selectrum.el @@ -782,8 +782,8 @@ PRED defaults to `minibuffer-completion-predicate'." (point-max) (point-max) (current-buffer)) (setq text (concat (or default " ") text)) (put-text-property 0 1 'cursor t text) - (overlay-put selectrum--candidates-overlay 'after-string text))) - (selectrum--update-minibuffer-height) + (overlay-put selectrum--candidates-overlay 'after-string text)) + (selectrum--update-minibuffer-height first-index-displayed)) (setq selectrum--end-of-input-marker (set-marker (make-marker) bound)) (set-marker-insertion-type selectrum--end-of-input-marker t) (selectrum--fix-set-minibuffer-message) @@ -791,8 +791,9 @@ PRED defaults to `minibuffer-completion-predicate'." (setq deactivate-mark nil)) (setq-local selectrum--init-p nil))) -(defun selectrum--update-minibuffer-height () - "Set minibuffer height for candidates display." +(defun selectrum--update-minibuffer-height (first) + "Set minibuffer height for candidates display. +FIRST is the index of the first displayed candidate." (let ((n (1+ selectrum-num-candidates-displayed)) (win (active-minibuffer-window))) ;; Set min initial height. @@ -800,12 +801,17 @@ PRED defaults to `minibuffer-completion-predicate'." selectrum--init-p) (with-selected-window win (setf (window-height) n))) - (let ((dheight (cdr (window-text-pixel-size win))) - (wheight (window-pixel-height win))) - ;; Grow if needed. - (when (> dheight wheight) - (window-resize - win (- dheight wheight) nil nil 'pixelwise))))) + ;; Grow if needed. + (when (or selectrum--init-p + ;; Don't allow growing while typing. + (and selectrum--current-candidate-index + (/= selectrum--current-candidate-index + first))) + (let ((dheight (cdr (window-text-pixel-size win))) + (wheight (window-pixel-height win))) + (when (> dheight wheight) + (window-resize + win (- dheight wheight) nil nil 'pixelwise)))))) (defun selectrum--first-lines (candidates) "Return list of single line CANDIDATES. From 5fce919e48985d530741618b3b895514ee221868 Mon Sep 17 00:00:00 2001 From: Clemens Radermacher Date: Wed, 5 Aug 2020 17:04:47 +0200 Subject: [PATCH 05/10] Allow shrinking while navigating --- selectrum.el | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/selectrum.el b/selectrum.el index 3b2e9c11..00ce5565 100644 --- a/selectrum.el +++ b/selectrum.el @@ -801,15 +801,16 @@ FIRST is the index of the first displayed candidate." selectrum--init-p) (with-selected-window win (setf (window-height) n))) - ;; Grow if needed. + ;; Adjust if needed (when (or selectrum--init-p - ;; Don't allow growing while typing. + ;; Allow size change when navigating but not while + ;; typing. (and selectrum--current-candidate-index (/= selectrum--current-candidate-index first))) (let ((dheight (cdr (window-text-pixel-size win))) (wheight (window-pixel-height win))) - (when (> dheight wheight) + (when (/= dheight wheight) (window-resize win (- dheight wheight) nil nil 'pixelwise)))))) From d3cb8ddc9694bf76cf6529299e47bdc6ae6d8fa3 Mon Sep 17 00:00:00 2001 From: Clemens Radermacher Date: Wed, 5 Aug 2020 17:19:56 +0200 Subject: [PATCH 06/10] Refactor --- selectrum.el | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/selectrum.el b/selectrum.el index 00ce5565..e7ebef5f 100644 --- a/selectrum.el +++ b/selectrum.el @@ -783,7 +783,9 @@ PRED defaults to `minibuffer-completion-predicate'." (setq text (concat (or default " ") text)) (put-text-property 0 1 'cursor t text) (overlay-put selectrum--candidates-overlay 'after-string text)) - (selectrum--update-minibuffer-height first-index-displayed)) + (selectrum--update-minibuffer-height first-index-displayed + highlighted-index + displayed-candidates)) (setq selectrum--end-of-input-marker (set-marker (make-marker) bound)) (set-marker-insertion-type selectrum--end-of-input-marker t) (selectrum--fix-set-minibuffer-message) @@ -791,9 +793,11 @@ PRED defaults to `minibuffer-completion-predicate'." (setq deactivate-mark nil)) (setq-local selectrum--init-p nil))) -(defun selectrum--update-minibuffer-height (first) +(defun selectrum--update-minibuffer-height (first highlighted cands) "Set minibuffer height for candidates display. -FIRST is the index of the first displayed candidate." +FIRST is the index of the first displayed candidate. HIGHLIGHTED +is the index if the highlighted candidate. CANDS are the +currently displayed candidates." (let ((n (1+ selectrum-num-candidates-displayed)) (win (active-minibuffer-window))) ;; Set min initial height. @@ -806,8 +810,9 @@ FIRST is the index of the first displayed candidate." ;; Allow size change when navigating but not while ;; typing. (and selectrum--current-candidate-index - (/= selectrum--current-candidate-index - first))) + (/= first highlighted) + (>= (length cands) + selectrum-num-candidates-displayed))) (let ((dheight (cdr (window-text-pixel-size win))) (wheight (window-pixel-height win))) (when (/= dheight wheight) From 97b588b604a75dbd8f01d46e3a6372f733b66049 Mon Sep 17 00:00:00 2001 From: Clemens Radermacher Date: Wed, 5 Aug 2020 17:37:49 +0200 Subject: [PATCH 07/10] Refine behaviour --- selectrum.el | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/selectrum.el b/selectrum.el index e7ebef5f..8822ea51 100644 --- a/selectrum.el +++ b/selectrum.el @@ -807,12 +807,13 @@ currently displayed candidates." (setf (window-height) n))) ;; Adjust if needed (when (or selectrum--init-p - ;; Allow size change when navigating but not while - ;; typing. (and selectrum--current-candidate-index + ;; Allow size change when navigating, not while + ;; typing. (/= first highlighted) - (>= (length cands) - selectrum-num-candidates-displayed))) + ;; Don't allow shrink for less candidates. + (= (length cands) + selectrum-num-candidates-displayed))) (let ((dheight (cdr (window-text-pixel-size win))) (wheight (window-pixel-height win))) (when (/= dheight wheight) From 6008c77e3f6fe206e476538b661863b4263f0300 Mon Sep 17 00:00:00 2001 From: Clemens Radermacher Date: Fri, 7 Aug 2020 14:10:21 +0200 Subject: [PATCH 08/10] Don' resize in minibuffer frames --- selectrum.el | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/selectrum.el b/selectrum.el index a6988f43..320eda04 100644 --- a/selectrum.el +++ b/selectrum.el @@ -803,25 +803,28 @@ is the index if the highlighted candidate. CANDS are the currently displayed candidates." (let ((n (1+ selectrum-num-candidates-displayed)) (win (active-minibuffer-window))) - ;; Set min initial height. - (when (and selectrum-fix-minibuffer-height - selectrum--init-p) - (with-selected-window win - (setf (window-height) n))) - ;; Adjust if needed - (when (or selectrum--init-p - (and selectrum--current-candidate-index - ;; Allow size change when navigating, not while - ;; typing. - (/= first highlighted) - ;; Don't allow shrink for less candidates. - (= (length cands) - selectrum-num-candidates-displayed))) - (let ((dheight (cdr (window-text-pixel-size win))) - (wheight (window-pixel-height win))) - (when (/= dheight wheight) - (window-resize - win (- dheight wheight) nil nil 'pixelwise)))))) + (when (and win + ;; don't try to resize a minibuffer frame + (not (frame-root-window-p win))) + ;; Set min initial height. + (when (and selectrum-fix-minibuffer-height + selectrum--init-p) + (with-selected-window win + (setf (window-height) n))) + ;; Adjust if needed + (when (or selectrum--init-p + (and selectrum--current-candidate-index + ;; Allow size change when navigating, not while + ;; typing. + (/= first highlighted) + ;; Don't allow shrink for less candidates. + (= (length cands) + selectrum-num-candidates-displayed))) + (let ((dheight (cdr (window-text-pixel-size win))) + (wheight (window-pixel-height win))) + (when (/= dheight wheight) + (window-resize + win (- dheight wheight) nil nil 'pixelwise))))))) (defun selectrum--first-lines (candidates) "Return list of single line CANDIDATES. From 8e50e89de825beba7ca54aae95c2e9c7e7840d5f Mon Sep 17 00:00:00 2001 From: Clemens Radermacher Date: Fri, 7 Aug 2020 14:15:10 +0200 Subject: [PATCH 09/10] Update comments --- selectrum.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/selectrum.el b/selectrum.el index 320eda04..62424f04 100644 --- a/selectrum.el +++ b/selectrum.el @@ -804,20 +804,20 @@ currently displayed candidates." (let ((n (1+ selectrum-num-candidates-displayed)) (win (active-minibuffer-window))) (when (and win - ;; don't try to resize a minibuffer frame + ;; Don't try to resize a minibuffer frame. (not (frame-root-window-p win))) ;; Set min initial height. (when (and selectrum-fix-minibuffer-height selectrum--init-p) (with-selected-window win (setf (window-height) n))) - ;; Adjust if needed + ;; Adjust if needed. (when (or selectrum--init-p (and selectrum--current-candidate-index ;; Allow size change when navigating, not while ;; typing. (/= first highlighted) - ;; Don't allow shrink for less candidates. + ;; Don't allow shrinking. (= (length cands) selectrum-num-candidates-displayed))) (let ((dheight (cdr (window-text-pixel-size win))) From 4e7eaadc4aa1ff601e2e77b0f04f8ab4f87883e2 Mon Sep 17 00:00:00 2001 From: Clemens Radermacher Date: Fri, 7 Aug 2020 14:18:04 +0200 Subject: [PATCH 10/10] Refactor --- selectrum.el | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/selectrum.el b/selectrum.el index 62424f04..02379d02 100644 --- a/selectrum.el +++ b/selectrum.el @@ -801,11 +801,10 @@ PRED defaults to `minibuffer-completion-predicate'." FIRST is the index of the first displayed candidate. HIGHLIGHTED is the index if the highlighted candidate. CANDS are the currently displayed candidates." - (let ((n (1+ selectrum-num-candidates-displayed)) - (win (active-minibuffer-window))) - (when (and win - ;; Don't try to resize a minibuffer frame. - (not (frame-root-window-p win))) + (when-let ((n (1+ selectrum-num-candidates-displayed)) + (win (active-minibuffer-window))) + ;; Don't attempt to resize a minibuffer frame. + (unless (frame-root-window-p win) ;; Set min initial height. (when (and selectrum-fix-minibuffer-height selectrum--init-p)