branch: elpa/dirvish
commit 5152c80a32de3965a3e131a9314514af4aa8aa1e
Author: Kit Dallege <[email protected]>
Commit: GitHub <[email protected]>

    Guard pre-redisplay hook to prevent multi-frame feedback loop (#371)
    
    `dirvish-pre-redisplay-h` is called via `pre-redisplay-functions` for
    every window that needs redisplay, but it unconditionally calls
    `dirvish--redisplay`.  When dirvish is open in multiple frames, this
    creates a feedback loop: frame A's redisplay triggers frame B's, and
    vice versa, causing visible flickering in the preview window.
    
    Guard the hook so it only fires for the selected window in its frame.
    
    Fix: #353
    
    Co-authored-by: Claude Opus 4.6 <[email protected]>
---
 dirvish.el | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/dirvish.el b/dirvish.el
index 062279d9a5..604158e681 100644
--- a/dirvish.el
+++ b/dirvish.el
@@ -1127,10 +1127,13 @@ Optionally, use CURSOR as the enabled cursor type."
                          (dirvish-use-header-line t))))))
 
 (defun dirvish-pre-redisplay-h (window)
-  "Record root WINDOW and redisplay sessions in selected frame."
-  (setq dirvish--selected-window (frame-selected-window))
-  (when-let* ((dv (dirvish-curr))) (setf (dv-root-window dv) window))
-  (dirvish--redisplay))
+  "Record root WINDOW and redisplay sessions in selected frame.
+Only act when WINDOW is the selected window in its frame to prevent
+a redisplay feedback loop when dirvish is open in multiple frames."
+  (when (eq (frame-selected-window) window)
+    (setq dirvish--selected-window window)
+    (when-let* ((dv (dirvish-curr))) (setf (dv-root-window dv) window))
+    (dirvish--redisplay)))
 
 (defun dirvish-post-command-h ()
   "Reset cursor shape and position and update preview."

Reply via email to