Skip to content

Keyboard shortcuts (ctrl+b, ctrl+i) breaks upon caps lock or fired when pressing ctrl + shift + b/i when caps lock is on #1177

Closed
@Eclipse-Dominator

Description

@Eclipse-Dominator

Describe the bug
When caps lock is turned on, the hotkeys mentioned in the title no longer functions

To Reproduce
Steps to reproduce the behavior:

  1. Go to any markdown editor tab
  2. Ensure caps lock is off
  3. Press Ctrl+I / command + I
  4. verify insertions of italic markdown syntax
  5. Toggle caps lock
  6. repeat step 3
  7. See italic markdown syntax no longer shown
  8. Press ctrl+shift+I
  9. See italic markdown syntax being shown

Expected behavior
Hotkeys should always fire regardless if Caps lock is toggled on or off. These hotkeys should not fire if the shift key is being held down.

Cause
This is caused by the use KeyboardEvent.key to check for key presses. Javascript will return the current key value when that key is pressed ("z" if caps lock is off and "Z" if caps lock is on) This causes current hotkey detection to fail when the caps lock is toggled.
I think the original intention of doing so is to account for the shift key where if the shift key is pressed when caps lock is off, the key value will be the capitalized version instead of the lowercase version. However, as mentioned in the issue, by toggling caps lock, not only will the hotkey fail to detect, but also cause ctrl+shift operators to be detected if caps lock is turned on.

Proposed fix
Replace the current detection to use KeyboardEvent.code instead which prevents caps lock from affecting the detection of keys as well as add in an additional check for shift keys.

Note
I believe that it is still possible to trigger keys like ctrl + <some other key> but it is a far less common for users to press those. I am not sure if there is a elegant way of detecting those.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions