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

refactor: separate some hotkey code into a library #83

Open
WofWca opened this issue Jul 14, 2022 · 0 comments
Open

refactor: separate some hotkey code into a library #83

WofWca opened this issue Jul 14, 2022 · 0 comments

Comments

@WofWca
Copy link
Owner

WofWca commented Jul 14, 2022

Like this, for example:

/**
* If a key is pressed while typing in an input field, we don't consider this a hotkey.
* Filter criteria is yoinked from
* https://github.com/ccampbell/mousetrap/blob/2f9a476ba6158ba69763e4fcf914966cc72ef433/mousetrap.js#L1000
* and alike libraries. Another reason to rewrite all this using a library.
*
* TODO how about we also/instead check if the target element is a parent of the video element that we're controlling?
*/
export function eventTargetIsInput(event: KeyboardEvent): boolean {
const t = event.target as Document | HTMLElement;
return (
['INPUT', 'SELECT', 'TEXTAREA']
// @ts-expect-error 2339 for performance because doing `'tagName' in t` would be redundant, because
// it is present most of the time.
.includes(t.tagName)
// @ts-expect-error 2339 same as above
|| t.isContentEditable
);
}

As stated in the comment, the criteria is already taken from another library.

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

1 participant