Skip to content

Commit 2bee235

Browse files
committed
feat: on click, place the cursor at the correct point after completion
1 parent 13f340c commit 2bee235

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

lsp-inline-completion.el

+14-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
(require 'lsp-protocol)
3232
(require 'dash)
3333
(require 'cl-lib)
34+
(require 'fringe)
3435

3536
(defun lsp-inline-completion--params (implicit &optional identifier position)
3637
"Returns a InlineCompletionParams instance"
@@ -69,7 +70,7 @@ InlineCompletionItem objects"
6970
(let ((map (make-sparse-keymap)))
7071
;; accept
7172
(define-key map (kbd "C-<return>") #'lsp-inline-completion-accept)
72-
(define-key map [mouse-1] #'lsp-inline-completion-accept)
73+
(define-key map [mouse-1] #'kzk/lsp-inline-completion-accept-on-click)
7374
;; navigate
7475
(define-key map (kbd "C-n") #'lsp-inline-completion-next)
7576
(define-key map (kbd "C-p") #'lsp-inline-completion-prev)
@@ -303,6 +304,18 @@ text range that was updated by the completion"
303304
;; hooks
304305
(run-hook-with-args-until-failure 'lsp-inline-completion-accepted-hook text text-insert-start text-insert-end)))
305306

307+
(defun kzk/lsp-inline-completion-accept-on-click (event)
308+
(interactive "e")
309+
310+
(lsp-inline-completion-accept)
311+
(-let (((col . row) (posn-actual-col-row (event-end event))))
312+
(move-to-window-line row)
313+
(beginning-of-line)
314+
(forward-char (- col
315+
(line-number-display-width)
316+
(fringe-columns 'left)
317+
1))))
318+
306319
(defun lsp-inline-completion-cancel ()
307320
"Close the suggestion overlay"
308321
(interactive)

0 commit comments

Comments
 (0)