Skip to content

Commit

Permalink
feat: use unread-command-events when cancelling inline completion
Browse files Browse the repository at this point in the history
When the inline completion handles `[t]`, we want it to tear down the
completion UI and act as if nothing had happened.

That works fine for single key events (escape, a-z (self-insert-command),
etc.).

Trying to use multi-key commands, on the other hand fails: If `C-x w q` is
bound (e.g. `quit-restore-window`), starting the key combination when inline
completion is active would result in cancel-with-input function being called
only with `C-x` as last-key. If we lookup C-x , it's not bound to a command,
so we do not execute anything. The user then proceeds to type `w q` and ends
up inserting the text "wq" instead of quitting the window.

This fixes that by using the unread-command-events -- that basically leaves
some input to be handled by the next iteration of the event loop.

As a result, we can now successfully call complex key combinations when the
inline completion is active.
  • Loading branch information
kassick committed Jan 17, 2025
1 parent 69803ce commit b3e5885
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions lsp-inline-completion.el
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ The functions receive the inserted text and the range that was updated by the co
(defun lsp-inline-completion-cancel ()
"Close the suggestion overlay."
(interactive)
(message nil) ;; clear echo
(let ((was-active (lsp-inline-completion--active-p)))
(lsp-inline-completion--clear-overlay)

Expand All @@ -326,11 +327,7 @@ The functions receive the inserted text and the range that was updated by the co

(lsp-inline-completion-cancel)

(let ((command (lookup-key (current-active-maps) (vector event)))
(current-prefix-arg arg))

(when (commandp command)
(call-interactively command))))
(setq unread-command-events (nconc unread-command-events (list event))))

(defun lsp-inline-completion-next ()
"Display the next inline completion."
Expand Down

0 comments on commit b3e5885

Please sign in to comment.