Skip to content

Commit d3b4a40

Browse files
authored
Merge pull request #239 from dgutov/show-hunk-updates
Some polish for `diff-hl-show-hunk`
2 parents c2852b0 + 47b3304 commit d3b4a40

3 files changed

Lines changed: 13 additions & 21 deletions

File tree

diff-hl-inline-popup.el

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ FOOTER are showed at start and end."
154154
diff-hl-inline-popup--current-footer)))
155155
;; https://debbugs.gnu.org/38563, `company--replacement-string'.
156156
(add-face-text-property 0 (length str) 'default t str)
157-
(overlay-put diff-hl-inline-popup--current-popup 'after-string str))))
157+
(put-text-property 0 1 'cursor 0 str)
158+
(overlay-put diff-hl-inline-popup--current-popup 'before-string str))))
158159

159160
(defun diff-hl-inline-popup--popup-down()
160161
"Scrolls one line down."

diff-hl-show-hunk-posframe.el

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,7 @@ Customize it to change the base properties of the text.")
7676
(interactive)
7777
(diff-hl-show-hunk-posframe--transient-mode -1)
7878
(when (frame-live-p diff-hl-show-hunk--frame)
79-
(make-frame-invisible diff-hl-show-hunk--frame))
80-
(when diff-hl-show-hunk--original-frame
81-
(when (frame-live-p diff-hl-show-hunk--original-frame)
82-
(let ((frame diff-hl-show-hunk--original-frame))
83-
(select-frame-set-input-focus frame)
84-
;; In Gnome, sometimes the input focus is not restored to the
85-
;; original frame, so we try harder in a while
86-
(run-with-timer 0.1 nil (lambda () (select-frame-set-input-focus frame)))))
87-
(setq diff-hl-show-hunk--original-frame nil)))
79+
(make-frame-invisible diff-hl-show-hunk--frame)))
8880

8981
(defvar diff-hl-show-hunk-posframe--transient-mode-map
9082
(let ((map (make-sparse-keymap)))
@@ -179,7 +171,6 @@ The button calls an ACTION."
179171
(user-error
180172
"Package `posframe' is not workable. Please customize diff-hl-show-hunk-function"))
181173

182-
(diff-hl-show-hunk--posframe-hide)
183174
(setq diff-hl-show-hunk--hide-function #'diff-hl-show-hunk--posframe-hide)
184175

185176
;; put an overlay to override read-only-mode keymap
@@ -194,8 +185,12 @@ The button calls an ACTION."
194185
(setq posframe-mouse-banish nil)
195186
(setq diff-hl-show-hunk--original-frame (selected-frame))
196187

197-
(let* ((hunk-overlay diff-hl-show-hunk--original-overlay)
198-
(position (overlay-end hunk-overlay)))
188+
(let* ((overlay diff-hl-show-hunk--original-overlay)
189+
(type (overlay-get overlay 'diff-hl-hunk-type))
190+
(position (save-excursion
191+
(goto-char (overlay-end overlay))
192+
(forward-line -1)
193+
(point))))
199194
(setq
200195
diff-hl-show-hunk--frame
201196
(posframe-show buffer
@@ -207,12 +202,12 @@ The button calls an ACTION."
207202
:internal-border-color diff-hl-show-hunk-posframe-internal-border-color
208203
:hidehandler nil
209204
;; Sometimes, header-line is not taken into account, so put a min height and a min width
210-
:min-height (when diff-hl-show-hunk-posframe-show-header-line 10)
211205
:min-width (when diff-hl-show-hunk-posframe-show-header-line
212206
(length (diff-hl-show-hunk-posframe--header-line)))
213207
:respect-header-line diff-hl-show-hunk-posframe-show-header-line
214208
:respect-tab-line nil
215209
:respect-mode-line nil
210+
:y-pixel-offset (if (eq type 'delete) (- (default-line-height)))
216211
:override-parameters diff-hl-show-hunk-posframe-parameters)))
217212

218213
(set-frame-parameter diff-hl-show-hunk--frame 'drag-internal-border t)
@@ -231,8 +226,7 @@ The button calls an ACTION."
231226
(setq cursor-type 'box)
232227

233228
;; Recenter around point
234-
(recenter)))
235-
(select-frame-set-input-focus diff-hl-show-hunk--frame))
229+
(recenter))))
236230

237231
(provide 'diff-hl-show-hunk-posframe)
238232
;;; diff-hl-show-hunk-posframe.el ends here

diff-hl-show-hunk.el

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,8 @@ end of the OVERLAY, so posframe/inline is placed below the hunk."
338338
(set-window-start nil (point)))
339339
((> (point) pt)
340340
(redisplay))))
341-
(goto-char (1- (overlay-end overlay)))))
341+
(goto-char (1- (overlay-end overlay)))
342+
(forward-line 0)))
342343

343344
;;;###autoload
344345
(defun diff-hl-show-hunk-next ()
@@ -361,10 +362,6 @@ end of the OVERLAY, so posframe/inline is placed below the hunk."
361362
The backend is determined by `diff-hl-show-hunk-function'."
362363
(interactive)
363364

364-
;; Close any previous hunk
365-
(save-excursion
366-
(diff-hl-show-hunk-hide))
367-
368365
(unless (vc-backend buffer-file-name)
369366
(user-error "The buffer is not under version control"))
370367

0 commit comments

Comments
 (0)