Fix/stale key state - #1
Merged
Merged
Conversation
…asing all keys helper function, make combos time out, dont error on key == undefined events
MichaelBuessemeyer
left a comment
Collaborator
Author
There was a problem hiding this comment.
some hints hopefully helping the reviewing process
Comment on lines
+86
to
+93
| // Composition keydowns (IME) and the placeholder keys some autofill | ||
| // implementations emit never receive a matching keyup, so tracking them could | ||
| // only ever strand a key. Note we never filter keyups: those can only ever | ||
| // remove state, and dropping one is what strands a key in the first place. | ||
| const cannotBeReleased = (event: KeyboardEvent) => | ||
| event.isComposing === true || | ||
| event.key === 'Process' || | ||
| event.key === 'Unidentified' |
Collaborator
Author
There was a problem hiding this comment.
guarding IME / browser autofill inputs
Comment on lines
+133
to
+150
| // blur does not cover every way a page can stop receiving key events, and any | ||
| // keyup delivered elsewhere in the meantime is lost. | ||
| const visibilityHandler = () => { | ||
| const doc = getDoc() as Partial<Document> | ||
| if (doc.visibilityState === 'hidden') handlerWrapper() | ||
| } | ||
|
|
||
| addEventListener('blur', handlerWrapper) | ||
| return () => removeEventListener('blur', handlerWrapper) | ||
| addEventListener('pagehide', handlerWrapper) | ||
| // visibilitychange is fired at the document, but it bubbles, so listening on | ||
| // the window keeps the document listener order untouched. | ||
| addEventListener('visibilitychange', visibilityHandler) | ||
|
|
||
| return () => { | ||
| removeEventListener('blur', handlerWrapper) | ||
| removeEventListener('pagehide', handlerWrapper) | ||
| removeEventListener('visibilitychange', visibilityHandler) | ||
| } |
Collaborator
Author
There was a problem hiding this comment.
new clean up handlers to reset recorded keys when page is left / blurred
| > = (handler) => { | ||
| try { | ||
| const handlerWrapper = (e: KeyboardEvent) => { | ||
| if (cannotBeReleased(e)) return |
Collaborator
Author
There was a problem hiding this comment.
guard against autofill / ime events
Comment on lines
+76
to
+79
| export const releaseAllKeys: typeof globalKeystrokes.releaseAllKeys = ( | ||
| ...args | ||
| ) => getGlobalKeystrokes().releaseAllKeys(...args) | ||
|
|
Collaborator
Author
There was a problem hiding this comment.
just let the lib expose releaseAllKeys for WK to be able to execute this if useful / needed
2 tasks
philippotto
approved these changes
Jul 31, 2026
philippotto
left a comment
Member
There was a problem hiding this comment.
I'm not really familiar with the code. Only skimmed the diff now. lgtm 👍
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR fixes some problems with the keystrokes library.
Bugs fixed:
To reproduce:
ctrl + k, wait 30 sec, pressb-> on master should active the brush tool as shortcutctrl + k, bwas triggered. Now this times out andb-> make branch point should trigger. See added tests.Changes
The changes are:
keyproperty of the event which might change while it is pressed due to additionally pressed modifier keys. Keys now have an identifier prop which iscode-> The key stable prop of such an event.Companion PR on WK side: scalableminds/webknossos#9842
@Reviewer I looked at the tests and the dist script. They should be fine. So code + readme is the only thing to look for imo and no testing needed. We need to test with in conjunction with the WK pr