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

Handle suffixes of cancelled keymaps in insert mode #8486

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kmicklas
Copy link
Contributor

@kmicklas kmicklas commented Oct 8, 2023

Fixes #2612. There are several potential design choices here, but I tried to strike a good balance between supporting this case, preserving existing behavior, and exhibiting reasonable behavior.

In particular, #2612 (comment) points out that, in the general case, it should be possible to cancel a pending key sequence by hitting any non-matched key, with no further effect. However, that was already violated by the existing behavior in insert mode, which would execute each key of a pending key sequence individually when cancelled. It seems like a bug that this never considered key sequences of length greater than one in any suffix of the sequence.

That property seems like it would be good to uphold where it doesn't interfere with expected insert typing, so as a compromise, I've made key sequences just cancel entirely if the first key isn't a regular character. This means that if a key sequence starts with a special character (e.g. an F key), then we assume the user wouldn't type it accidentally by trying to insert text (like is common with escape sequences like fd, jk, etc.).

@kmicklas kmicklas marked this pull request as ready for review October 9, 2023 19:56
@pascalkuthe
Copy link
Member

pascalkuthe commented Oct 12, 2023

See also #6960 and #6878

this issue is not specific to insertmode

@kmicklas
Copy link
Contributor Author

See also #6960 and #6878

Looking just at insert mode, I think the approach in this PR is more general than #6878. The problem is not specific to the last character in a sequence. That is only equivalent when the sequence only has length two.

this issue is not specific to insertmode

"Fixing" this in normal mode seems like it could cause problems. If I cancel a key sequence in normal mode, I don't want it to try to execute some suffix of the key sequence, which could have arbitrary effect that is hard to predict.

Technically this concern exists in insert mode too, but there we have to balance it against the desire to support sequences like jk/fd. In insert mode we also have good reason to expect that the user wants to execute a "keymap suffix" - they just wanted to type the prefix as regular characters. This wouldn't make sense in normal mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Issue with [keys.insert] mappings such as j = { f = "normal_mode" }
3 participants