Skip to content

Commit 435f8e5

Browse files
committed
dap-mouse: use overlays
`add-text-properties' and `remove-text-properties' cause the buffer to be modified. Use overlays for dap's hover tooltips instead. Fixes #391.
1 parent cbe6549 commit 435f8e5

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

dap-mouse.el

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ If there is an active selection - return it."
132132
(goto-char point)
133133
(bounds-of-thing-at-point 'symbol))))
134134

135-
(defvar-local dap-tooltip-bounds nil)
135+
(defvar-local dap--tooltip-overlay nil)
136136
(defun dap-tooltip-post-tooltip ()
137137
"Clean tooltip properties."
138138

@@ -146,24 +146,21 @@ If there is an active selection - return it."
146146
(lambda ()
147147
(when (dap-mouse--hide-popup?)
148148
(posframe-hide dap-mouse-buffer)
149-
(when dap-tooltip-bounds
150-
(remove-text-properties (car dap-tooltip-bounds)
151-
(cdr dap-tooltip-bounds)
152-
'(mouse-face))
149+
(when dap--tooltip-overlay
150+
(delete-overlay dap--tooltip-overlay)
153151
;; restore the selection
154152
(when (region-active-p)
155-
(let ((bounds dap-tooltip-bounds))
153+
(let ((start (overlay-start dap--tooltip-overlay))
154+
(end (overlay-end dap--tooltip-overlay)))
156155
(run-with-idle-timer
157156
0.0
158157
nil
159158
(lambda ()
160159
(let ((point (point)))
161-
(push-mark (car bounds) t t)
162-
(goto-char (cdr bounds))
160+
(push-mark start t t)
161+
(goto-char end)
163162
(unless (= point (point))
164-
(exchange-point-and-mark)))))))
165-
(setq dap-tooltip-bounds nil))
166-
163+
(exchange-point-and-mark))))))))
167164
(setq dap-mouse--hide-timer nil)
168165
(remove-hook 'post-command-hook #'dap-tooltip-post-tooltip)))))))
169166

@@ -183,7 +180,6 @@ consequently where to show the `posframe'."
183180
(bounds (dap-tooltip-thing-bounds mouse-point))
184181
((start . end) bounds)
185182
(expression (s-trim (buffer-substring start end))))
186-
(setq dap-tooltip-bounds bounds)
187183
(dap--send-message
188184
(dap--make-request "evaluate"
189185
(list :expression expression
@@ -192,8 +188,9 @@ consequently where to show the `posframe'."
192188
(dap--resp-handler
193189
(-lambda ((&hash "body" (&hash? "result"
194190
"variablesReference" variables-reference)))
195-
(add-text-properties
196-
start end '(mouse-face dap-mouse-eval-thing-face))
191+
(setq dap--tooltip-overlay
192+
(-doto (make-overlay start end)
193+
(overlay-put 'mouse-face 'dap-mouse-eval-thing-face)))
197194
;; Show a dead buffer so that the `posframe' size is consistent.
198195
(when (get-buffer dap-mouse-buffer)
199196
(kill-buffer dap-mouse-buffer))

0 commit comments

Comments
 (0)