Skip to content

Conversation

@nagygeri97
Copy link

  • Ensure that pressing F1-F12 doesn't type it's value
  • Start and stop player with space in practice mode
  • Start and stop first unsolved player in daily mode


let pressedKey = String(e.key)
let found = pressedKey.match(/[a-z]/gi)
let found = pressedKey.match(/^[a-z]$/gi)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if this is the best way to check this though. Regex are relatively costly and slow for something like this, wouldn't it be more efficient just check that the input is within the range a to z, which causes JS to compare the ascii key code? i.e. pressedKey >= 'a' && pressedKey <= 'z'.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, not really. regex isnt that costly. if we really needed to change it than something like

pressedKey.toUpperCase() != char.toLowerCase() || pressedKey.codePointAt(0) > 127

@nagygeri97 nagygeri97 force-pushed the key-handling-improvements branch from ef60d89 to fc861bb Compare January 28, 2024 21:15
* Ensure that pressing F1-F12 doesn't type it's value
* Start and stop player with space in practice, spelloff and youtube modes
* Start and stop first unsolved player with space in daily mode
@nagygeri97 nagygeri97 force-pushed the key-handling-improvements branch from fc861bb to 5928baa Compare January 28, 2024 21:20
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

Successfully merging this pull request may close these issues.

3 participants