mirror of
https://github.com/atom/atom.git
synced 2026-01-22 21:38:10 -05:00
Normalize keystrokes to use shift and the uppercase letter
`cmd-shift-l`, `cmd-L` and `cmd-shift-L` all normalize to `cmd-shift-L`
This commit is contained in:
@@ -270,6 +270,14 @@ describe "Keymap", ->
|
||||
expect(result).toBe(false)
|
||||
expect(fooHandler).toHaveBeenCalled()
|
||||
|
||||
it "normalizes bindings that use an upper case alpha char without shift", ->
|
||||
fooHandler = jasmine.createSpy('fooHandler')
|
||||
fragment.on 'foo', fooHandler
|
||||
keymap.bindKeys 'name', '*', 'ctrl-L': 'foo'
|
||||
result = keymap.handleKeyEvent(keydownEvent('l', ctrlKey: true, altKey: false, shiftKey: true, target: fragment[0]))
|
||||
expect(result).toBe(false)
|
||||
expect(fooHandler).toHaveBeenCalled()
|
||||
|
||||
it "normalizes the key patterns in the hash to put the modifiers in alphabetical order", ->
|
||||
fooHandler = jasmine.createSpy('fooHandler')
|
||||
fragment.on 'foo', fooHandler
|
||||
@@ -322,7 +330,7 @@ describe "Keymap", ->
|
||||
|
||||
describe "when shift is pressed when a non-modifer key", ->
|
||||
it "returns a string that identifies the key pressed", ->
|
||||
expect(keymap.keystrokeStringForEvent(keydownEvent('A', shiftKey: true))).toBe 'A'
|
||||
expect(keymap.keystrokeStringForEvent(keydownEvent('A', shiftKey: true))).toBe 'shift-A'
|
||||
expect(keymap.keystrokeStringForEvent(keydownEvent('{', shiftKey: true))).toBe '{'
|
||||
expect(keymap.keystrokeStringForEvent(keydownEvent('left', shiftKey: true))).toBe 'shift-left'
|
||||
expect(keymap.keystrokeStringForEvent(keydownEvent('Left', shiftKey: true))).toBe 'shift-left'
|
||||
|
||||
@@ -23,9 +23,9 @@ class KeyBinding
|
||||
modifiers.sort()
|
||||
key = _.last(keys)
|
||||
|
||||
# Uppercase alpha chars if the shift modifer is pressed
|
||||
if 'shift' in modifiers and /^[a-z]$/i.test(key)
|
||||
modifiers = _.without(modifiers, 'shift')
|
||||
# Add the shift modifier if the key is an uppercased alpha char
|
||||
if /^[A-Z]$/.test(key) or 'shift' in modifiers
|
||||
modifiers.push 'shift' unless 'shift' in modifiers
|
||||
key = key.toUpperCase()
|
||||
[modifiers..., key].join('-')
|
||||
|
||||
|
||||
@@ -99,10 +99,12 @@ class Keymap
|
||||
modifiers.push 'cmd'
|
||||
if event.ctrlKey and key not in Modifiers
|
||||
modifiers.push 'ctrl'
|
||||
|
||||
if event.shiftKey and key not in Modifiers
|
||||
isNamedKey = key.length > 1
|
||||
modifiers.push 'shift' if isNamedKey
|
||||
# Don't push the shift modifier on single letter non-alpha keys (e.g. { or ')
|
||||
modifiers.push 'shift' unless /^[^a-z]$/i.test(key)
|
||||
|
||||
if 'shift' in modifiers and /^[a-z]$/i.test(key)
|
||||
key = key.toUpperCase()
|
||||
else
|
||||
key = key.toLowerCase()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user