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

Keypresses race #343

Open
CosineP opened this issue Aug 12, 2024 · 2 comments
Open

Keypresses race #343

CosineP opened this issue Aug 12, 2024 · 2 comments

Comments

@CosineP
Copy link

CosineP commented Aug 12, 2024

Hi folks -

First of all, I want to thank you all for allowing me to use VSCode! I have long been hopelessly kakoune-pilled, and when I last tried VSCode there was no useful kakoune extension, so this is a huge win.

Here is the problem I am having: if my laptop gets below 20% (and tlp throttles my CPU), when I issue a bunch of commands they will occur in a fairly random order. The result is that I have to wait for the editor to respond after each keypress before I can press the next one if I want a consistent result.

Here's an easy way to reproduce: put your cursor at the beginning of a long line. Hold "e". If your cursor repeat is fast enough and your computer isn't a supercomputer, then your cursor jumps around to various ends of words, ending up at the end of a random word. (This happens to me even at full charge.)

If you allow me to bloviate for a moment, I can only assume this is because the handler for each keypress is issued asynchronously, but the effects are not await-ed before the next keypress is handled.

This is breaking for me when my laptop is under 20%, but over 20% usually the keypresses issue quickly enough to not matter. Current workaround is keep my laptop charged, because I really like this extension, but I still see races sometimes when I type really quickly. Fixing this would also allow dance to work on less powerful machines.

@sgraf812
Copy link

I'm seeing the same, but on my desktop machine as well, so I would not say it's related to "less powerful" machines.

For me, a good reproducer is opening a file and keep pressing j. As soon as the cursor hits the bottom line of the viewport, scrolling slows down and the cursor jumps around in circles due to the race condition. It's quite annoying.

@sgraf812
Copy link

If I'm not mistaken, this code currently implements j:

if (count === 0 || count === 1) {
Selections.updateByIndex((_, selection) => {
let line = Selections.activeLine(selection);
if (Selections.isEntireLines(selection) && !selection.isReversed) {
line++;
}
return new vscode.Selection(line, 0, line + 1, 0);
});

Perhaps it would be better to maintain a globally coherent array of selections that is asynchronously updated with diffs.
I think that's what VSCodeVim does. At least they are using cursorMove commands to update the cursor position with a diff rather than with an updated position:

https://github.com/VSCodeVim/Vim/blob/33ac373dde7d14260d0ac1133bf1ba25a39dd556/src/actions/motion.ts#L85

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

No branches or pull requests

2 participants