emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/consult 44fc1236a2: Improve robustness of preview


From: ELPA Syncer
Subject: [elpa] externals/consult 44fc1236a2: Improve robustness of preview
Date: Sat, 9 Sep 2023 06:57:36 -0400 (EDT)

branch: externals/consult
commit 44fc1236a2a4386ec7d2329807258f13dfed094a
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    Improve robustness of preview
    
    Check that the miniwindow is still selected when the preview timer elapsed. 
This
    additional checks improves interaction with the new vertico-suspend command.
---
 consult.el | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/consult.el b/consult.el
index 489c628f89..5bc505ccaf 100644
--- a/consult.el
+++ b/consult.el
@@ -1675,7 +1675,8 @@ PREVIEW-KEY, STATE, TRANSFORM and CANDIDATE."
                 (funcall state 'setup nil))
               (setq consult--preview-function
                     (lambda ()
-                      (when-let ((cand (funcall candidate)))
+                      (when-let ((cand (funcall candidate))
+                                 (mbwin (active-minibuffer-window)))
                         ;; Drop properties to prevent bugs regarding candidate
                         ;; lookup, which must handle candidates without
                         ;; properties.  Otherwise the arguments passed to the
@@ -1683,10 +1684,11 @@ PREVIEW-KEY, STATE, TRANSFORM and CANDIDATE."
                         ;; the candidate has properties but for the final 
lookup
                         ;; after completion it does not.
                         (setq cand (substring-no-properties cand))
-                        (with-selected-window (active-minibuffer-window)
+                        (with-selected-window mbwin
                           (let ((input (minibuffer-contents-no-properties))
-                                (narrow consult--narrow))
-                            (with-selected-window (or 
(minibuffer-selected-window) (next-window))
+                                (narrow consult--narrow)
+                                (pwin (or (minibuffer-selected-window) 
(next-window))))
+                            (with-selected-window pwin
                               (when-let ((transformed (funcall transform 
narrow input cand))
                                          (debounce 
(consult--preview-key-debounce preview-key transformed)))
                                 (when timer
@@ -1710,15 +1712,17 @@ PREVIEW-KEY, STATE, TRANSFORM and CANDIDATE."
                                 ;; the thing which is actually previewed.
                                 (unless (equal-including-properties previewed 
transformed)
                                   (if (> debounce 0)
-                                      (let ((win (selected-window)))
-                                        (setq timer
-                                              (run-at-time
-                                               debounce nil
-                                               (lambda ()
-                                                 (when (window-live-p win)
-                                                   (with-selected-window win
-                                                     ;; STEP 2: Preview 
candidate
-                                                     (funcall state 'preview 
(setq previewed transformed))))))))
+                                      (setq timer
+                                            (run-at-time
+                                             debounce nil
+                                             (lambda ()
+                                               ;; Only preview when the 
minibuffer is selected
+                                               ;; and when the preview window 
is alive.
+                                               (when (and (eq 
(selected-window) mbwin)
+                                                          (window-live-p pwin))
+                                                 (with-selected-window pwin
+                                                   ;; STEP 2: Preview candidate
+                                                   (funcall state 'preview 
(setq previewed transformed)))))))
                                     ;; STEP 2: Preview candidate
                                     (funcall state 'preview (setq previewed 
transformed)))))))))))
               (consult--preview-append-local-pch



reply via email to

[Prev in Thread] Current Thread [Next in Thread]