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 keymap async command sequence execution order #4244

Closed
wants to merge 1 commit into from

Conversation

kl
Copy link

@kl kl commented Oct 13, 2022

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 and count 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 just register and count but that is not possible because Context is not 'static but EditorView is. Any thoughts on this? Feedback is appreciated!

fixes #4013

@kl kl force-pushed the keymap_commands_execution_order branch from 8e1758a to 34132c4 Compare October 13, 2022 11:08
@kirawi kirawi added C-bug Category: This is a bug A-helix-term Area: Helix term improvements S-waiting-on-review Status: Awaiting review from a maintainer. labels Oct 15, 2022
Comment on lines 1401 to 1402
if !self.pending_commands.commands.is_empty()
&& command_status == commands::CommandStatus::Finished
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that returning CommandStatus is not necessary: we can detect if there is another on-next-key callback by checking if cx.on_next_key.is_some()

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you're right. 👍 I removed that part of the code and rebased on latest master.

@kl kl force-pushed the keymap_commands_execution_order branch from 34132c4 to 4bd2f38 Compare November 20, 2022 11:15
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.
@pascalkuthe
Copy link
Member

Clsoing this PR as stale. This also doesn't cover all the cases and is ultimaetly blocked by some larger architectureal changes (see ##4709).

Thank you for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements C-bug Category: This is a bug S-waiting-on-review Status: Awaiting review from a maintainer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow chaining find_next_char, select_textobject_around, etc. together with other commands in keymaps
4 participants