Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #217 from atom/b3-fix-caps-lock-issues
Browse files Browse the repository at this point in the history
Deal with caps lock issues on Windows
  • Loading branch information
Nathan Sobo committed Aug 7, 2017
2 parents 057ef82 + 635516d commit c7b62d1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 2 additions & 0 deletions spec/keymap-manager-spec.coffee
Expand Up @@ -649,6 +649,8 @@ describe "KeymapManager", ->
assert.equal(keymapManager.keystrokeForKeyboardEvent(buildKeydownEvent({key: 'a', shiftKey: true})), 'shift-A')
assert.equal(keymapManager.keystrokeForKeyboardEvent(buildKeydownEvent({key: 'a', shiftKey: true, altKey: true})), 'alt-shift-A')
assert.equal(keymapManager.keystrokeForKeyboardEvent(buildKeydownEvent({key: 'a', shiftKey: true, ctrlKey: true})), 'ctrl-shift-A')
it "doesn't drop the ctrl-alt modifiers when there is no AltGraph variant", ->
assert.equal(keymapManager.keystrokeForKeyboardEvent(buildKeydownEvent({key: 'p', shiftKey: true, altKey: true, ctrlKey: true})), 'ctrl-alt-shift-P')

describe "when the KeyboardEvent.key is 'Delete' but KeyboardEvent.code is 'Backspace' due to pressing ctrl-delete with numlock enabled on Windows", ->
it "translates as ctrl-backspace instead of ctrl-delete", ->
Expand Down
15 changes: 7 additions & 8 deletions src/helpers.coffee
Expand Up @@ -156,6 +156,13 @@ exports.keystrokeForKeyboardEvent = (event, customKeystrokeResolvers) ->
if isNonCharacterKey
key = NON_CHARACTER_KEY_NAMES_BY_KEYBOARD_EVENT_KEY[key] ? key.toLowerCase()
else
# Deal with caps-lock issues. Key bindings should always adjust the
# capitalization of the key based on the shiftKey state and never the state
# of the caps-lock key
if shiftKey
key = key.toUpperCase()
else
key = key.toLowerCase()
if event.getModifierState('AltGraph') or (process.platform is 'darwin' and altKey)
# All macOS layouts have an alt-modified character variant for every
# single key. Therefore, if we always favored the alt variant, it would
Expand Down Expand Up @@ -192,14 +199,6 @@ exports.keystrokeForKeyboardEvent = (event, customKeystrokeResolvers) ->
key = nonAltModifiedKey
altKey = event.getModifierState('AltGraph')

# Deal with caps-lock issues. Key bindings should always adjust the
# capitalization of the key based on the shiftKey state and never the state
# of the caps-lock key
if shiftKey
key = key.toUpperCase()
else
key = key.toLowerCase()

# Use US equivalent character for non-latin characters in keystrokes with modifiers
# or when using the dvorak-qwertycmd layout and holding down the command key.
if (key.length is 1 and not isLatinKeymap(KeyboardLayout.getCurrentKeymap())) or
Expand Down

0 comments on commit c7b62d1

Please sign in to comment.