Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: the self-insert command in vi-mode should not insert un-printable char while flushing the pending-keys #1701

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions extensions/vi-mode/vi-mode.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,29 @@
(this-command-keys (vi-this-command-keys))
(pending-keys (cdr this-command-keys)))

;; For the command `self-insert`, the `this-command-keys` is typically only 1 char. (pending-keys = nil)
;; If pending-keys is NOT nil, then these keys are used to disguish the keys between `self-insert` command and other commands.
;; For other commands, we can simply ignore the pending-keys.
;; For self-insert command, we should also flusthese pending-keys.
;; NOTE: In `vim`, if you define `jk` as `Escape` in insert-mode. The effect is:
;; 1. In vi-insert-mode, press `j` and `k` will escape from insert-mode to normal-mode.
;; 2. In vi-insert-mode, press `j` and `<second-key>` will:
;; a. If `<second-key>` is print-able-key, taken `e` key for example, then will self-insert `j` and self-insert `e`.
;; b. If `<second-key>` is un-print-able-key, taken `Backspace` key for example, then will cancel the self-insert `j` and remain in vi-insert-mode.

;; FIXME: In `lem` impl, the `2.b` case will not cancel the self-insert of `j` key, because the code is written in post-command-hook, we have no chance to cancel the executing of `self-insert` command for the first-key.
;;
;;
;;
;; For self-insert command, we should also flush the pending-keys.
;; 1. Typically, the length of`this-command-keys` is only 1 key. (pending-keys = nil)
;; 2. If the length of `this-command-keys` > 1 key (pending-keys is not nil, they are used to disguish `self-insert` command and other commands), we need to flush `pending-keys`.
(when (and
(typep command 'self-insert)
pending-keys)
(dolist (key pending-keys) (self-insert 1 (key-to-char key))))
(loop :for key :in pending-keys
;; FIXME: the `named-key` is not identical to `print-able-key`. (Taken `Tab` key for example)
:until (named-key-sym-p (key-sym key))
:do
(self-insert 1 (key-to-char key))))



(when *enable-repeat-recording*
(unless (or (and (typep command 'vi-command)
Expand Down
Loading