From 2d73f80781b96c26338b155effcdc886871f0df0 Mon Sep 17 00:00:00 2001 From: sakurawald Date: Tue, 10 Dec 2024 11:33:39 +0800 Subject: [PATCH 1/3] fix: the self-insert command in vi-mode should not insert un-printable char while flushing the pending-keys --- extensions/vi-mode/vi-mode.lisp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/extensions/vi-mode/vi-mode.lisp b/extensions/vi-mode/vi-mode.lisp index 591c55370..928f5ac6e 100644 --- a/extensions/vi-mode/vi-mode.lisp +++ b/extensions/vi-mode/vi-mode.lisp @@ -77,7 +77,10 @@ (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 + :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) From dc58b01e3b06c68f2edbd46ad458171ab85103b5 Mon Sep 17 00:00:00 2001 From: sakurawald Date: Tue, 10 Dec 2024 13:23:08 +0800 Subject: [PATCH 2/3] add: comments for self-insert flushing in vi-insert-mode --- extensions/vi-mode/vi-mode.lisp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/extensions/vi-mode/vi-mode.lisp b/extensions/vi-mode/vi-mode.lisp index 928f5ac6e..064f1dfaf 100644 --- a/extensions/vi-mode/vi-mode.lisp +++ b/extensions/vi-mode/vi-mode.lisp @@ -70,7 +70,15 @@ (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) + ;; 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 `` will: + ;; a. If `` is print-able-key, taken `e` key for example, then will self-insert `j` and self-insert `e`. + ;; b. If `` 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 change to cancel the executing of `self-insert` command for the first-key. + + ;; For the command `self-insert`, the `this-command-keys` is typically only 1 key. (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. @@ -78,6 +86,7 @@ (typep command 'self-insert) pending-keys) (loop :for key :in pending-keys + ;; FIXME: the `named-key` is no 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)))) From 45cc18488e597023b9ef3d9e8cb7826cb525c983 Mon Sep 17 00:00:00 2001 From: sakurawald Date: Tue, 10 Dec 2024 17:08:56 +0800 Subject: [PATCH 3/3] refactor: rephrase comments for self-insert flushing in vi-insert-mode --- extensions/vi-mode/vi-mode.lisp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/extensions/vi-mode/vi-mode.lisp b/extensions/vi-mode/vi-mode.lisp index 064f1dfaf..8b2994e4e 100644 --- a/extensions/vi-mode/vi-mode.lisp +++ b/extensions/vi-mode/vi-mode.lisp @@ -76,21 +76,24 @@ ;; a. If `` is print-able-key, taken `e` key for example, then will self-insert `j` and self-insert `e`. ;; b. If `` 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 change to cancel the executing of `self-insert` command for the first-key. - - ;; For the command `self-insert`, the `this-command-keys` is typically only 1 key. (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. + ;; 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) (loop :for key :in pending-keys - ;; FIXME: the `named-key` is no identical to `print-able-key`. (Taken `Tab` key for example) + ;; 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) (eq (vi-command-repeat command) nil))