Fix keymap async command sequence execution order #4244
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If a keymap triggered a command sequence and the sequence contained a command that needs user input, the following commands were executed before the command that was waiting for input, which resulted in commands being executed in the wrong order.
This commit fixes that by checking if a command is waiting for input and if so storing the remaining commands in the editor and executing them after the
on_next_key
callback has been called.One slightly tricky part is that I also opted to store some context state along with the pending commands (that is the values of
register
andcount
as they were when the command sequence was first executed). These values are then restored on the context object when the pending commands are resumed, so that they get the original context state. If more state is added to the context in the future this state also needs to be added and restored when executing pending commands (which would be easy to forget). A better option would be to store the entire context object instead of justregister
andcount
but that is not possible becauseContext
is not 'static butEditorView
is. Any thoughts on this? Feedback is appreciated!fixes #4013