branch: elpa/dirvish
commit 885c2d84b48a52c8042d9289e11ee7757a930590
Author: zsxh <bnbvbc...@gmail.com>
Commit: Alex Lu <hellosimon1...@hotmail.com>

    perf(peek): prevent redundant updates by tracking previous candidate
    
    Added a new variable `dirvish-peek-pre-cand` to track the previously
    displayed candidate. The peek window will now only update when the
    candidate changes, preventing redundant updates when navigating
    through directories. Also resets `dirvish-peek-pre-cand` when cleaning
    up peek sessions.
---
 extensions/dirvish-peek.el | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/extensions/dirvish-peek.el b/extensions/dirvish-peek.el
index 1ec9a9805e..48e3cd17d2 100644
--- a/extensions/dirvish-peek.el
+++ b/extensions/dirvish-peek.el
@@ -72,10 +72,13 @@ one of categories in `dirvish-peek-categories'."
         (setf (dv-preview-window new-dv)
               (or (minibuffer-selected-window) (next-window)))))))
 
+(defvar dirvish-peek--prev-cand nil)
 (defun dirvish-peek-update-h ()
   "Hook for `post-command-hook' to update peek window."
   (when-let* ((dirvish-peek--curr-category)
-              (cand (funcall dirvish-peek--cand-fetcher)))
+              (cand (funcall dirvish-peek--cand-fetcher))
+              ((not (string= cand dirvish-peek--prev-cand))))
+    (setq dirvish-peek--prev-cand cand)
     (pcase dirvish-peek--curr-category
       ('file
        (setq cand (expand-file-name cand)))
@@ -94,7 +97,8 @@ one of categories in `dirvish-peek-categories'."
   (dolist (dv (hash-table-values dirvish--session-hash))
     (when (eq (dv-type dv) 'peek)
       (dirvish--clear-session dv)
-      (remhash (dv-name dv) dirvish--session-hash))))
+      (remhash (dv-name dv) dirvish--session-hash)))
+  (setq dirvish-peek--prev-cand nil))
 
 ;;;###autoload
 (define-minor-mode dirvish-peek-mode

Reply via email to