fix(vc): better line selection in git-timemachine buffers when browse at remote

`+vc/browse-at-remote` on git-timemachine buffers solely depended on the active
region to determine highlighted lines in the browser, sometimes returning an
error when no region is set, and other times using an implicit/invisible
transient mark. The number of lines that get highlighted at remote is also not
always consistent.

This commit modifies `+vc-support-git-timemachine-a` to correct all the above
and have `+vc/browse-at-remote` remain consistent between git-timemachine
buffers and non git-timemachine buffers.
This commit is contained in:
Eyoel Tesfu
2025-04-29 07:04:22 -05:00
committed by Henrik Lissner
parent 30501abd59
commit 2b1e07dcf0

View File

@ -89,8 +89,10 @@
file in your browser at the visited revision."
:around #'browse-at-remote-get-url
(if git-timemachine-mode
(let* ((start-line (line-number-at-pos (min (region-beginning) (region-end))))
(end-line (line-number-at-pos (max (region-beginning) (region-end))))
(let* ((start-line (and (use-region-p) (line-number-at-pos
(min (region-beginning) (region-end)))))
(point-end (and (use-region-p) (max (region-beginning) (region-end))))
(end-line (and (use-region-p) (line-number-at-pos point-end)))
(remote-ref (browse-at-remote--remote-ref buffer-file-name))
(remote (car remote-ref))
(ref (car git-timemachine-revision))
@ -105,7 +107,8 @@ file in your browser at the visited revision."
(error (format "Origin repo parsing failed: %s" repo-url)))
(funcall url-formatter repo-url ref relname
(if start-line start-line)
(if (and end-line (not (equal start-line end-line))) end-line)))
(when (and end-line (not (equal start-line end-line)))
(if (eq (char-before point-end) ?\n) (- end-line 1) end-line))))
(funcall fn)))
(defadvice! +vc-update-header-line-a (revision)