Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions spec/keymap-manager-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ describe "KeymapManager", ->
assert.equal(keymapManager.keystrokeForKeyboardEvent({key: 'Backspace'}), 'backspace')
assert.equal(keymapManager.keystrokeForKeyboardEvent({key: 'Delete'}), 'delete')
assert.equal(keymapManager.keystrokeForKeyboardEvent({key: 'PageUp'}), 'pageup')
assert.equal(keymapManager.keystrokeForKeyboardEvent({key: ' ', code: 'Space'}), 'space')

describe "when a modifier key is combined with a non-modifier key", ->
it "returns a string that identifies the modified keystroke", ->
Expand Down
10 changes: 8 additions & 2 deletions src/helpers.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ KeyboardLayout = require 'keyboard-layout'
MODIFIERS = new Set(['ctrl', 'alt', 'shift', 'cmd'])
ENDS_IN_MODIFIER_REGEX = /(ctrl|alt|shift|cmd)$/
WHITESPACE_REGEX = /\s+/
KEY_NAMES_BY_KEYBOARD_EVENT_CODE = {
'Space': 'space'
}
NON_CHARACTER_KEY_NAMES_BY_KEYBOARD_EVENT_KEY = {
'Control': 'ctrl',
'Meta': 'cmd',
Expand Down Expand Up @@ -95,7 +98,7 @@ parseKeystroke = (keystroke) ->
keys

exports.keystrokeForKeyboardEvent = (event) ->
{key, ctrlKey, altKey, shiftKey, metaKey} = event
{key, code, ctrlKey, altKey, shiftKey, metaKey} = event

if key is 'Dead'
if process.platform isnt 'linux' and characters = KeyboardLayout.getCurrentKeymap()[event.code]
Expand All @@ -110,9 +113,12 @@ exports.keystrokeForKeyboardEvent = (event) ->
else if characters.unmodified?
key = characters.unmodified

if KEY_NAMES_BY_KEYBOARD_EVENT_CODE[code]?
key = KEY_NAMES_BY_KEYBOARD_EVENT_CODE[code]

isNonCharacterKey = key.length > 1
if isNonCharacterKey
key = NON_CHARACTER_KEY_NAMES_BY_KEYBOARD_EVENT_KEY[event.key] ? event.key.toLowerCase()
key = NON_CHARACTER_KEY_NAMES_BY_KEYBOARD_EVENT_KEY[key] ? key.toLowerCase()
else
if altKey
# All macOS layouts have an alt-modified character variant for every
Expand Down