From 2bee235906b4d6e74e174d36d8c915a8fe615fd1 Mon Sep 17 00:00:00 2001 From: Rodrigo Kassick Date: Thu, 28 Nov 2024 20:51:32 -0300 Subject: [PATCH] feat: on click, place the cursor at the correct point after completion --- lsp-inline-completion.el | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lsp-inline-completion.el b/lsp-inline-completion.el index dcd181db812..d8cdde3d62d 100644 --- a/lsp-inline-completion.el +++ b/lsp-inline-completion.el @@ -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" @@ -69,7 +70,7 @@ InlineCompletionItem objects" (let ((map (make-sparse-keymap))) ;; accept (define-key map (kbd "C-") #'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) @@ -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)