branch: elpa/magit
commit cd79c7be4c817cfc22d9e4cfbce53b3ce6fb89ee
Author: Jonas Bernoulli <jo...@bernoul.li>
Commit: Jonas Bernoulli <jo...@bernoul.li>

    Coordinate highlighting between refresh and post-command phases
    
    1. When a buffer is refreshed, section highlighting has to be updated.
    2. More than one buffer may be refreshed at the same time and the
       current buffer may or may not be among them.
    3. Therefore highlighting has to happen during the refresh phase.
    4. However, re-highlighting can also be necessary when not refresh
       took place (or at least the current buffer wasn't refreshed.
    5. Therefore re-highlighting has to happen during the post-command
       phase, which happens after every command in a Magit buffer.
    
    We may therefore end up refreshing the same buffer twice.  To avoid that
    record when a buffer is refreshed and during the post-command phase skip
    highlighting such buffers before zpping the list of refreshed buffers.
    
    A weaker attempt to accomplish this was already in place, but checking
    whether `this-command' is a refresh command does not cast a wide enough
    net.
    
    Instead of recording buffers that have been refreshed and highlighted,
    we could not highlight during the refresh phase and instead record
    buffers as needing to be highlighted during the post-command phase.
---
 lisp/magit-mode.el    | 3 ++-
 lisp/magit-section.el | 8 ++++++--
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/lisp/magit-mode.el b/lisp/magit-mode.el
index 20d62b2bce..eb73f7ff21 100644
--- a/lisp/magit-mode.el
+++ b/lisp/magit-mode.el
@@ -1110,7 +1110,8 @@ Run hooks `magit-pre-refresh-hook' and 
`magit-post-refresh-hook'."
                 (apply #'magit-section-goto-successor args)))))
         (run-hooks 'magit-refresh-buffer-hook)
         (magit-section-update-highlight)
-        (set-buffer-modified-p nil))
+        (set-buffer-modified-p nil)
+        (push buffer magit-section--refreshed-buffers))
       (when magit-refresh-verbose
         (message "Refreshing buffer `%s'...done (%.3fs)" (buffer-name)
                  (float-time (time-since magit--refresh-start-time)))))))
diff --git a/lisp/magit-section.el b/lisp/magit-section.el
index b53996ca52..d18e7e0e09 100644
--- a/lisp/magit-section.el
+++ b/lisp/magit-section.el
@@ -1679,6 +1679,8 @@ evaluated its BODY.  Admittedly that's a bit of a hack."
 
 ;;; Highlight
 
+(defvar magit-section--refreshed-buffers nil)
+
 (defun magit-section-pre-command-hook ()
   (when (and (or magit--context-menu-buffer
                  magit--context-menu-section)
@@ -1692,6 +1694,7 @@ evaluated its BODY.  Admittedly that's a bit of a hack."
     ;; after the menu is aborted.  Here we can only make sure it is
     ;; updated afterwards.
     (magit-menu-highlight-point-section))
+  (setq magit-section--refreshed-buffers nil)
   (setq magit-section-pre-command-region-p (region-active-p))
   (setq magit-section-pre-command-section (magit-current-section))
   (setq magit-section-focused-sections nil))
@@ -1705,8 +1708,9 @@ evaluated its BODY.  Admittedly that's a bit of a hack."
       (when (or magit--context-menu-buffer
                 magit--context-menu-section)
         (magit-menu-highlight-point-section))))
-  (unless (memq this-command '(magit-refresh magit-refresh-all))
-    (magit-section-update-highlight)))
+  (unless (memq (current-buffer) magit-section--refreshed-buffers)
+    (magit-section-update-highlight))
+  (setq magit-section--refreshed-buffers nil))
 
 (defun magit-section-deactivate-mark ()
   (setq magit-section-highlight-force-update t))

Reply via email to