Skip to content

Commit

Permalink
feat: on click, place the cursor at the correct point after completion
Browse files Browse the repository at this point in the history
  • Loading branch information
kassick committed Nov 28, 2024
1 parent 13f340c commit 2bee235
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lsp-inline-completion.el
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
(require 'lsp-protocol)
(require 'dash)
(require 'cl-lib)
(require 'fringe)

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

(defun kzk/lsp-inline-completion-accept-on-click (event)
(interactive "e")

(lsp-inline-completion-accept)
(-let (((col . row) (posn-actual-col-row (event-end event))))
(move-to-window-line row)
(beginning-of-line)
(forward-char (- col
(line-number-display-width)
(fringe-columns 'left)
1))))

(defun lsp-inline-completion-cancel ()
"Close the suggestion overlay"
(interactive)
Expand Down

0 comments on commit 2bee235

Please sign in to comment.