helix icon indicating copy to clipboard operation
helix copied to clipboard

Fix keymap async command sequence execution order

Open kl opened this issue 3 years ago • 0 comments

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!

related issue: #4013

kl avatar Oct 13 '22 10:10 kl