-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
Issues with key sequences #4
base: master
Are you sure you want to change the base?
Conversation
It took a while to take a look at this, but now I have. First of all I can't run the tests with bun, it just stays stuck here: First testThe first test is basically this: test ( 'key sequences do not trigger single key shortcuts', async () => {
let f_pressed = 0;
let g_pressed = 0;
let fg_pressed = 0;
const sho = new ShoSho ();
sho.register('f', () => { f_pressed++; });
sho.register('g', () => { g_pressed++; });
sho.register('f g', () => { fg_pressed++; return true });
sho.start()
keypress('f')
expect(f_pressed).toEqual(1)
await new Promise(resolve => setTimeout(() => resolve(''), 1000));
keypress('g')
expect(g_pressed).toEqual(1)
expect(fg_pressed).toEqual(0)
keypress('f')
keypress('g')
expect(f_pressed).toEqual(1)
expect(g_pressed).toEqual(1)
expect(fg_pressed).toEqual(1)
}) Going step by step: keypress('f')
expect(f_pressed).toEqual(1) We trigger We wait 1 second, that doesn't change anything, shosho doesn't care about timings like that. Then we do this: keypress('g')
expect(g_pressed).toEqual(1)
expect(fg_pressed).toEqual(0) We trigger Lastly we do this: keypress('f')
keypress('g')
expect(f_pressed).toEqual(1)
expect(g_pressed).toEqual(1)
expect(fg_pressed).toEqual(1) In some sense I see where you are coming from, So basically the first test is wrong, shosho is working as expected here, it's just not time-sensitive like that, so the two scenarios, with and without the 1s delay, are identical to it. Second testFirst we do this, and it works as expected: keypress('f')
keypress('g')
expect(fg_pressed).toEqual(1)
expect(fh_pressed).toEqual(0) Then we do this, and it also works as expected: keypress('f')
keypress('h')
expect(fg_pressed).toEqual(1)
expect(fh_pressed).toEqual(1) Lastly we do this: keypress('g')
keypress('h')
expect(fg_pressed).toEqual(1)
expect(fh_pressed).toEqual(1) And Lines 236 to 240 in 28c00ed
The thing is I don't remember exactly why those lines look like that, I'm going to need to look at this again tomorrow with a fresher mind. Right now I'm thinking that if the chord got handled we should always reset the current list of chords with a In general we could definitely benefit from some automated tests, this stuff is tricky to test so for now I've been doing some manual tests. The thing is also that I want to see the library working if a switch to different layouts, those kinds of tests would be a nightmare to automate. |
I think I stumbled upon two issues in ShoSho that I couldn't get resolved. There might be an issue in ShoSho, or I might use it wrong.
I couldn't get ShoSho to run with fava, so I added some very basic bun/happydom tests to illustrate these issues.