From ca35cfaf725f5b34f164f37de7637f17681fe2a4 Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Sat, 10 May 2025 04:44:09 +0300 Subject: [PATCH 1/4] Unify behavior between diff-hl-show-hunk-function's * Move posframe one line up, so its popup starts right after the hunk. * Add the same exception for `deletion` that inline-popup has. * Use `before-string` and `cursor` in inline popup, for correct positioning of it with `deletion` hunks as well. And of cursor, which it overlaps. --- diff-hl-inline-popup.el | 3 ++- diff-hl-show-hunk-posframe.el | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/diff-hl-inline-popup.el b/diff-hl-inline-popup.el index 48a6f991..0f202aff 100644 --- a/diff-hl-inline-popup.el +++ b/diff-hl-inline-popup.el @@ -154,7 +154,8 @@ FOOTER are showed at start and end." diff-hl-inline-popup--current-footer))) ;; https://debbugs.gnu.org/38563, `company--replacement-string'. (add-face-text-property 0 (length str) 'default t str) - (overlay-put diff-hl-inline-popup--current-popup 'after-string str)))) + (put-text-property 0 1 'cursor 0 str) + (overlay-put diff-hl-inline-popup--current-popup 'before-string str)))) (defun diff-hl-inline-popup--popup-down() "Scrolls one line down." diff --git a/diff-hl-show-hunk-posframe.el b/diff-hl-show-hunk-posframe.el index 331c4bb3..014d3f26 100644 --- a/diff-hl-show-hunk-posframe.el +++ b/diff-hl-show-hunk-posframe.el @@ -194,8 +194,12 @@ The button calls an ACTION." (setq posframe-mouse-banish nil) (setq diff-hl-show-hunk--original-frame (selected-frame)) - (let* ((hunk-overlay diff-hl-show-hunk--original-overlay) - (position (overlay-end hunk-overlay))) + (let* ((overlay diff-hl-show-hunk--original-overlay) + (type (overlay-get overlay 'diff-hl-hunk-type)) + (position (save-excursion + (goto-char (overlay-end overlay)) + (forward-line -1) + (point)))) (setq diff-hl-show-hunk--frame (posframe-show buffer @@ -213,6 +217,7 @@ The button calls an ACTION." :respect-header-line diff-hl-show-hunk-posframe-show-header-line :respect-tab-line nil :respect-mode-line nil + :y-pixel-offset (if (eq type 'delete) (- (default-line-height))) :override-parameters diff-hl-show-hunk-posframe-parameters))) (set-frame-parameter diff-hl-show-hunk--frame 'drag-internal-border t) From e42d0153123d89779191bec6f15697c99c1eea6f Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Sat, 10 May 2025 05:25:08 +0300 Subject: [PATCH 2/4] diff-hl-show-hunk--posframe-hide: Remove GNOME workaround Couldn't reproduce the problem, and this code caused the original frame to be selected after several calls to diff-hl-show-hunk-next, for example (because after the first one diff-hl-show-hunk--frame becomes non-nil, so we got a timer which goes back to the original frame). --- diff-hl-show-hunk-posframe.el | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/diff-hl-show-hunk-posframe.el b/diff-hl-show-hunk-posframe.el index 014d3f26..f5f24e2e 100644 --- a/diff-hl-show-hunk-posframe.el +++ b/diff-hl-show-hunk-posframe.el @@ -76,15 +76,7 @@ Customize it to change the base properties of the text.") (interactive) (diff-hl-show-hunk-posframe--transient-mode -1) (when (frame-live-p diff-hl-show-hunk--frame) - (make-frame-invisible diff-hl-show-hunk--frame)) - (when diff-hl-show-hunk--original-frame - (when (frame-live-p diff-hl-show-hunk--original-frame) - (let ((frame diff-hl-show-hunk--original-frame)) - (select-frame-set-input-focus frame) - ;; In Gnome, sometimes the input focus is not restored to the - ;; original frame, so we try harder in a while - (run-with-timer 0.1 nil (lambda () (select-frame-set-input-focus frame))))) - (setq diff-hl-show-hunk--original-frame nil))) + (make-frame-invisible diff-hl-show-hunk--frame))) (defvar diff-hl-show-hunk-posframe--transient-mode-map (let ((map (make-sparse-keymap))) From a4913bb3ef54efe52990cbcd0a20ce6cc5235fba Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Sun, 11 May 2025 01:50:03 +0300 Subject: [PATCH 3/4] Reduce blinkiness during show-hunk's next/previous jumps * Don't call diff-hl-show-hunk--posframe-hide when (re)showing hunk, let the rendering code take care of that. * Move point to beginning of indentation in diff-hl-show-hunk--goto-hunk-overlay. Less chance to trigger show-paren-mode highlights, and a more logical position anyway. * Don't select-frame-set-input-focus at the end of diff-hl-show-hunk-posframe. Removes the cursor blink between the frames, while keys and button pressed still get processed the same. --- diff-hl-show-hunk-posframe.el | 4 +--- diff-hl-show-hunk.el | 7 ++----- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/diff-hl-show-hunk-posframe.el b/diff-hl-show-hunk-posframe.el index f5f24e2e..9f25c9e8 100644 --- a/diff-hl-show-hunk-posframe.el +++ b/diff-hl-show-hunk-posframe.el @@ -171,7 +171,6 @@ The button calls an ACTION." (user-error "Package `posframe' is not workable. Please customize diff-hl-show-hunk-function")) - (diff-hl-show-hunk--posframe-hide) (setq diff-hl-show-hunk--hide-function #'diff-hl-show-hunk--posframe-hide) ;; put an overlay to override read-only-mode keymap @@ -228,8 +227,7 @@ The button calls an ACTION." (setq cursor-type 'box) ;; Recenter around point - (recenter))) - (select-frame-set-input-focus diff-hl-show-hunk--frame)) + (recenter)))) (provide 'diff-hl-show-hunk-posframe) ;;; diff-hl-show-hunk-posframe.el ends here diff --git a/diff-hl-show-hunk.el b/diff-hl-show-hunk.el index 3e82e102..8f50b420 100644 --- a/diff-hl-show-hunk.el +++ b/diff-hl-show-hunk.el @@ -338,7 +338,8 @@ end of the OVERLAY, so posframe/inline is placed below the hunk." (set-window-start nil (point))) ((> (point) pt) (redisplay)))) - (goto-char (1- (overlay-end overlay))))) + (goto-char (1- (overlay-end overlay))) + (forward-line 0))) ;;;###autoload (defun diff-hl-show-hunk-next () @@ -361,10 +362,6 @@ end of the OVERLAY, so posframe/inline is placed below the hunk." The backend is determined by `diff-hl-show-hunk-function'." (interactive) - ;; Close any previous hunk - (save-excursion - (diff-hl-show-hunk-hide)) - (unless (vc-backend buffer-file-name) (user-error "The buffer is not under version control")) From 47b33048be01cfa62a1dd2e60e3afb8f076395c6 Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Sun, 11 May 2025 01:51:38 +0300 Subject: [PATCH 4/4] diff-hl-show-hunk-posframe: Don't specify min-height The avoids the big blank space when the hunk is short. --- diff-hl-show-hunk-posframe.el | 1 - 1 file changed, 1 deletion(-) diff --git a/diff-hl-show-hunk-posframe.el b/diff-hl-show-hunk-posframe.el index 9f25c9e8..48ea54b4 100644 --- a/diff-hl-show-hunk-posframe.el +++ b/diff-hl-show-hunk-posframe.el @@ -202,7 +202,6 @@ The button calls an ACTION." :internal-border-color diff-hl-show-hunk-posframe-internal-border-color :hidehandler nil ;; Sometimes, header-line is not taken into account, so put a min height and a min width - :min-height (when diff-hl-show-hunk-posframe-show-header-line 10) :min-width (when diff-hl-show-hunk-posframe-show-header-line (length (diff-hl-show-hunk-posframe--header-line))) :respect-header-line diff-hl-show-hunk-posframe-show-header-line