branch: elpa/magit
commit 142e6330166614b191b7f94b765c90e74610b3f3
Author: Jonas Bernoulli <[email protected]>
Commit: Jonas Bernoulli <[email protected]>

    magit-status-goto-file-position: Favor unstaged hunk
    
    If a matching unstaged hunk is found and the line is modified in that,
    use that position.  Otherwise a matching unstaged hunk is found and
    the line is modified in that, use that position.  I.e., favor unstaged
    changes, but if the line is modified in the staged changes but not in
    the unstaged changes, then favor the staged hunk which last modified
    the line in question -- not the unstaged hunk that happens to modify
    some close by line.
    
    If the line is modified in neither the unstaged nor staged changes,
    again favor the former over the latter, but this time ignoring line
    precision.
    
    Finally as before, if no hunk containing the line is found, find the
    file, again favoring unstaged over staged changes.  As before go either
    to the heading of the file or the heading of the last hunk, depending
    on whether the line in question comes before or after the modified
    lines.
    
    Before this commit we favored staged changes over unstaged changes,
    but that made little sense.
    
    Closes #4814.
---
 lisp/magit-status.el | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/lisp/magit-status.el b/lisp/magit-status.el
index e301002245c..ca99dcdbc07 100644
--- a/lisp/magit-status.el
+++ b/lisp/magit-status.el
@@ -470,13 +470,16 @@ Type \\[magit-commit] to create a commit.
       (list file (line-number-at-pos) (current-column)))))
 
 (defun magit-status--goto-file-position (file line column)
-  (pcase-let ((`(,upos ,_uhunk)
+  (pcase-let ((`(,upos ,uloc)
                (magit-diff--locate-file-position file line column 'unstaged))
-              (`(,spos ,shunk)
+              (`(,spos ,sloc)
                (magit-diff--locate-file-position file line column 'staged)))
-    (cond (shunk (goto-char spos))
-          (upos  (goto-char upos))
-          (spos  (goto-char spos)))
+    (cond ((eq uloc 'line) (goto-char upos))
+          ((eq sloc 'line) (goto-char spos))
+          ((eq uloc 'hunk) (goto-char upos))
+          ((eq sloc 'hunk) (goto-char spos))
+          (upos            (goto-char upos))
+          (spos            (goto-char spos)))
     (when (or upos spos)
       (magit-section-reveal (magit-current-section)))))
 

Reply via email to