atom-keymap
Advanced tools
Comparing version 6.3.2 to 6.3.3-beta0
34
api.json
@@ -6,3 +6,3 @@ { | ||
"filename": "src/keymap-manager.coffee", | ||
"srcUrl": "https://github.com/atom/atom-keymap/blob/v6.3.2/src/keymap-manager.coffee#L66", | ||
"srcUrl": "https://github.com/atom/atom-keymap/blob/v6.3.3-beta0/src/keymap-manager.coffee#L66", | ||
"sections": [ | ||
@@ -42,3 +42,3 @@ { | ||
"sectionName": "Class Methods", | ||
"srcUrl": "https://github.com/atom/atom-keymap/blob/v6.3.2/src/keymap-manager.coffee#L83", | ||
"srcUrl": "https://github.com/atom/atom-keymap/blob/v6.3.3-beta0/src/keymap-manager.coffee#L83", | ||
"visibility": "Public", | ||
@@ -105,3 +105,3 @@ "summary": "Create a keydown DOM event for testing purposes.", | ||
"sectionName": "Construction and Destruction", | ||
"srcUrl": "https://github.com/atom/atom-keymap/blob/v6.3.2/src/keymap-manager.coffee#L109", | ||
"srcUrl": "https://github.com/atom/atom-keymap/blob/v6.3.3-beta0/src/keymap-manager.coffee#L109", | ||
"visibility": "Public", | ||
@@ -130,3 +130,3 @@ "summary": "Create a new KeymapManager.", | ||
"sectionName": "Construction and Destruction", | ||
"srcUrl": "https://github.com/atom/atom-keymap/blob/v6.3.2/src/keymap-manager.coffee#L117", | ||
"srcUrl": "https://github.com/atom/atom-keymap/blob/v6.3.3-beta0/src/keymap-manager.coffee#L117", | ||
"visibility": "Public", | ||
@@ -139,3 +139,3 @@ "summary": "Clear all registered key bindings and enqueued keystrokes. For use\nin tests. ", | ||
"sectionName": "Construction and Destruction", | ||
"srcUrl": "https://github.com/atom/atom-keymap/blob/v6.3.2/src/keymap-manager.coffee#L125", | ||
"srcUrl": "https://github.com/atom/atom-keymap/blob/v6.3.3-beta0/src/keymap-manager.coffee#L125", | ||
"visibility": "Public", | ||
@@ -148,3 +148,3 @@ "summary": "Unwatch all watched paths. ", | ||
"sectionName": "Event Subscription", | ||
"srcUrl": "https://github.com/atom/atom-keymap/blob/v6.3.2/src/keymap-manager.coffee#L151", | ||
"srcUrl": "https://github.com/atom/atom-keymap/blob/v6.3.3-beta0/src/keymap-manager.coffee#L151", | ||
"visibility": "Public", | ||
@@ -199,3 +199,3 @@ "summary": "Invoke the given callback when one or more keystrokes completely\nmatch a key binding.", | ||
"sectionName": "Event Subscription", | ||
"srcUrl": "https://github.com/atom/atom-keymap/blob/v6.3.2/src/keymap-manager.coffee#L167", | ||
"srcUrl": "https://github.com/atom/atom-keymap/blob/v6.3.3-beta0/src/keymap-manager.coffee#L167", | ||
"visibility": "Public", | ||
@@ -250,3 +250,3 @@ "summary": "Invoke the given callback when one or more keystrokes partially\nmatch a binding.", | ||
"sectionName": "Event Subscription", | ||
"srcUrl": "https://github.com/atom/atom-keymap/blob/v6.3.2/src/keymap-manager.coffee#L181", | ||
"srcUrl": "https://github.com/atom/atom-keymap/blob/v6.3.3-beta0/src/keymap-manager.coffee#L181", | ||
"visibility": "Public", | ||
@@ -295,3 +295,3 @@ "summary": "Invoke the given callback when one or more keystrokes fail to match\nany bindings.", | ||
"sectionName": "Event Subscription", | ||
"srcUrl": "https://github.com/atom/atom-keymap/blob/v6.3.2/src/keymap-manager.coffee#L212", | ||
"srcUrl": "https://github.com/atom/atom-keymap/blob/v6.3.3-beta0/src/keymap-manager.coffee#L212", | ||
"visibility": "Public", | ||
@@ -340,3 +340,3 @@ "summary": "Invoke the given callback when a keymap file not able to be loaded.", | ||
"sectionName": "Adding and Removing Bindings", | ||
"srcUrl": "https://github.com/atom/atom-keymap/blob/v6.3.2/src/keymap-manager.coffee#L227", | ||
"srcUrl": "https://github.com/atom/atom-keymap/blob/v6.3.3-beta0/src/keymap-manager.coffee#L227", | ||
"visibility": "Public", | ||
@@ -369,3 +369,3 @@ "summary": "Add sets of key bindings grouped by CSS selector.", | ||
"sectionName": "Accessing Bindings", | ||
"srcUrl": "https://github.com/atom/atom-keymap/blob/v6.3.2/src/keymap-manager.coffee#L266", | ||
"srcUrl": "https://github.com/atom/atom-keymap/blob/v6.3.3-beta0/src/keymap-manager.coffee#L266", | ||
"visibility": "Public", | ||
@@ -384,3 +384,3 @@ "summary": "Get all current key bindings.", | ||
"sectionName": "Accessing Bindings", | ||
"srcUrl": "https://github.com/atom/atom-keymap/blob/v6.3.2/src/keymap-manager.coffee#L281", | ||
"srcUrl": "https://github.com/atom/atom-keymap/blob/v6.3.3-beta0/src/keymap-manager.coffee#L281", | ||
"visibility": "Public", | ||
@@ -427,3 +427,3 @@ "summary": "Get the key bindings for a given command and optional target.", | ||
"sectionName": "Managing Keymap Files", | ||
"srcUrl": "https://github.com/atom/atom-keymap/blob/v6.3.2/src/keymap-manager.coffee#L318", | ||
"srcUrl": "https://github.com/atom/atom-keymap/blob/v6.3.3-beta0/src/keymap-manager.coffee#L318", | ||
"visibility": "Public", | ||
@@ -464,3 +464,3 @@ "summary": "Load the key bindings from the given path.", | ||
"sectionName": "Managing Keymap Files", | ||
"srcUrl": "https://github.com/atom/atom-keymap/blob/v6.3.2/src/keymap-manager.coffee#L341", | ||
"srcUrl": "https://github.com/atom/atom-keymap/blob/v6.3.3-beta0/src/keymap-manager.coffee#L341", | ||
"visibility": "Public", | ||
@@ -495,3 +495,3 @@ "summary": "Cause the keymap to reload the key bindings file at the given path\nwhenever it changes.", | ||
"sectionName": "Managing Keyboard Events", | ||
"srcUrl": "https://github.com/atom/atom-keymap/blob/v6.3.2/src/keymap-manager.coffee#L413", | ||
"srcUrl": "https://github.com/atom/atom-keymap/blob/v6.3.3-beta0/src/keymap-manager.coffee#L413", | ||
"visibility": "Public", | ||
@@ -512,3 +512,3 @@ "summary": "Dispatch a custom event associated with the matching key binding for\nthe given `KeyboardEvent` if one can be found.", | ||
"sectionName": "Managing Keyboard Events", | ||
"srcUrl": "https://github.com/atom/atom-keymap/blob/v6.3.2/src/keymap-manager.coffee#L625", | ||
"srcUrl": "https://github.com/atom/atom-keymap/blob/v6.3.3-beta0/src/keymap-manager.coffee#L625", | ||
"visibility": "Public", | ||
@@ -535,3 +535,3 @@ "summary": "Translate a keydown event to a keystroke string.", | ||
"sectionName": "Managing Keyboard Events", | ||
"srcUrl": "https://github.com/atom/atom-keymap/blob/v6.3.2/src/keymap-manager.coffee#L632", | ||
"srcUrl": "https://github.com/atom/atom-keymap/blob/v6.3.3-beta0/src/keymap-manager.coffee#L632", | ||
"visibility": "Public", | ||
@@ -538,0 +538,0 @@ "summary": "Get the number of milliseconds allowed before pending states caused\nby partial matches of multi-keystroke bindings are terminated.", |
(function() { | ||
var AtomModifierRegex, AtomModifiers, ExactMatch, KeyboardEventModifiers, KeydownExactMatch, LowerCaseLetterRegex, NumPadToASCII, PartialMatch, UpperCaseLetterRegex, WhitespaceRegex, WindowsAndLinuxCharCodeTranslations, WindowsAndLinuxKeyIdentifierTranslations, calculateSpecificity, charCodeFromKeyIdentifier, isASCII, keyForKeyboardEvent, keyFromCharCode, keyboardEvent, modifier, normalizeKeystroke, numpadToASCII, parseKeystroke, translateCharCodeForWindowsAndLinuxChromiumBug, translateKeyIdentifierForWindowsAndLinuxChromiumBug, _i, _j, _len, _len1, _ref, _ref1; | ||
var ENDS_IN_MODIFIER_REGEX, KeyboardLayout, MATCH_TYPES, MODIFIERS, NON_CHARACTER_KEY_NAMES_BY_KEYBOARD_EVENT_KEY, WHITESPACE_REGEX, buildKeyboardEvent, calculateSpecificity, isASCIICharacter, isLatinCharacter, isLowerCaseCharacter, isUpperCaseCharacter, normalizeKeystroke, parseKeystroke, usCharactersForKeyCode, usKeymap; | ||
calculateSpecificity = require('clear-cut').calculateSpecificity; | ||
AtomModifiers = new Set; | ||
KeyboardLayout = require('keyboard-layout'); | ||
_ref = ['ctrl', 'alt', 'shift', 'cmd']; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
modifier = _ref[_i]; | ||
AtomModifiers.add(modifier); | ||
} | ||
MODIFIERS = new Set(['ctrl', 'alt', 'shift', 'cmd']); | ||
AtomModifierRegex = /(ctrl|alt|shift|cmd)$/; | ||
ENDS_IN_MODIFIER_REGEX = /(ctrl|alt|shift|cmd)$/; | ||
WhitespaceRegex = /\s+/; | ||
WHITESPACE_REGEX = /\s+/; | ||
LowerCaseLetterRegex = /^[a-z]$/; | ||
NON_CHARACTER_KEY_NAMES_BY_KEYBOARD_EVENT_KEY = { | ||
'Control': 'ctrl', | ||
'Meta': 'cmd', | ||
'ArrowDown': 'down', | ||
'ArrowUp': 'up', | ||
'ArrowLeft': 'left', | ||
'ArrowRight': 'right' | ||
}; | ||
UpperCaseLetterRegex = /^[A-Z]$/; | ||
MATCH_TYPES = { | ||
EXACT: 'exact', | ||
KEYDOWN_EXACT: 'keydownExact', | ||
PARTIAL: 'partial' | ||
}; | ||
ExactMatch = 'exact'; | ||
isASCIICharacter = function(character) { | ||
return (character != null) && character.length === 1 && character.charCodeAt(0) <= 127; | ||
}; | ||
KeydownExactMatch = 'keydownExact'; | ||
isLatinCharacter = function(character) { | ||
return (character != null) && character.length === 1 && character.charCodeAt(0) <= 0x024F; | ||
}; | ||
PartialMatch = 'partial'; | ||
isUpperCaseCharacter = function(character) { | ||
return (character != null) && character.length === 1 && character.toLowerCase() !== character; | ||
}; | ||
KeyboardEventModifiers = new Set; | ||
isLowerCaseCharacter = function(character) { | ||
return (character != null) && character.length === 1 && character.toUpperCase() !== character; | ||
}; | ||
_ref1 = ['Control', 'Alt', 'Shift', 'Meta']; | ||
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { | ||
modifier = _ref1[_j]; | ||
KeyboardEventModifiers.add(modifier); | ||
} | ||
usKeymap = null; | ||
WindowsAndLinuxKeyIdentifierTranslations = { | ||
'U+00A0': 'Shift', | ||
'U+00A1': 'Shift', | ||
'U+00A2': 'Control', | ||
'U+00A3': 'Control', | ||
'U+00A4': 'Alt', | ||
'U+00A5': 'Alt', | ||
'Win': 'Meta' | ||
}; | ||
WindowsAndLinuxCharCodeTranslations = { | ||
48: { | ||
shifted: 41, | ||
unshifted: 48 | ||
}, | ||
49: { | ||
shifted: 33, | ||
unshifted: 49 | ||
}, | ||
50: { | ||
shifted: 64, | ||
unshifted: 50 | ||
}, | ||
51: { | ||
shifted: 35, | ||
unshifted: 51 | ||
}, | ||
52: { | ||
shifted: 36, | ||
unshifted: 52 | ||
}, | ||
53: { | ||
shifted: 37, | ||
unshifted: 53 | ||
}, | ||
54: { | ||
shifted: 94, | ||
unshifted: 54 | ||
}, | ||
55: { | ||
shifted: 38, | ||
unshifted: 55 | ||
}, | ||
56: { | ||
shifted: 42, | ||
unshifted: 56 | ||
}, | ||
57: { | ||
shifted: 40, | ||
unshifted: 57 | ||
}, | ||
186: { | ||
shifted: 58, | ||
unshifted: 59 | ||
}, | ||
187: { | ||
shifted: 43, | ||
unshifted: 61 | ||
}, | ||
188: { | ||
shifted: 60, | ||
unshifted: 44 | ||
}, | ||
189: { | ||
shifted: 95, | ||
unshifted: 45 | ||
}, | ||
190: { | ||
shifted: 62, | ||
unshifted: 46 | ||
}, | ||
191: { | ||
shifted: 63, | ||
unshifted: 47 | ||
}, | ||
192: { | ||
shifted: 126, | ||
unshifted: 96 | ||
}, | ||
219: { | ||
shifted: 123, | ||
unshifted: 91 | ||
}, | ||
220: { | ||
shifted: 124, | ||
unshifted: 92 | ||
}, | ||
221: { | ||
shifted: 125, | ||
unshifted: 93 | ||
}, | ||
222: { | ||
shifted: 34, | ||
unshifted: 39 | ||
usCharactersForKeyCode = function(code) { | ||
if (usKeymap == null) { | ||
usKeymap = require('./us-keymap'); | ||
} | ||
return usKeymap[code]; | ||
}; | ||
NumPadToASCII = { | ||
79: 47, | ||
74: 42, | ||
77: 45, | ||
75: 43, | ||
78: 46, | ||
96: 48, | ||
65: 49, | ||
66: 50, | ||
67: 51, | ||
68: 52, | ||
69: 53, | ||
70: 54, | ||
71: 55, | ||
72: 56, | ||
73: 57 | ||
}; | ||
exports.normalizeKeystrokes = function(keystrokes) { | ||
var keystroke, normalizedKeystroke, normalizedKeystrokes, _k, _len2, _ref2; | ||
var keystroke, normalizedKeystroke, normalizedKeystrokes, _i, _len, _ref; | ||
normalizedKeystrokes = []; | ||
_ref2 = keystrokes.split(WhitespaceRegex); | ||
for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) { | ||
keystroke = _ref2[_k]; | ||
_ref = keystrokes.split(WHITESPACE_REGEX); | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
keystroke = _ref[_i]; | ||
if (normalizedKeystroke = normalizeKeystroke(keystroke)) { | ||
@@ -166,11 +69,128 @@ normalizedKeystrokes.push(normalizedKeystroke); | ||
exports.keystrokeForKeyboardEvent = function(event, dvorakQwertyWorkaroundEnabled) { | ||
var key, keystroke; | ||
key = keyForKeyboardEvent(event, dvorakQwertyWorkaroundEnabled); | ||
normalizeKeystroke = function(keystroke) { | ||
var i, isKeyup, key, keys, modifiers, primaryKey, _i, _len; | ||
if (isKeyup = keystroke.startsWith('^')) { | ||
keystroke = keystroke.slice(1); | ||
} | ||
keys = parseKeystroke(keystroke); | ||
if (!keys) { | ||
return false; | ||
} | ||
primaryKey = null; | ||
modifiers = new Set; | ||
for (i = _i = 0, _len = keys.length; _i < _len; i = ++_i) { | ||
key = keys[i]; | ||
if (MODIFIERS.has(key)) { | ||
modifiers.add(key); | ||
} else { | ||
if (i === keys.length - 1) { | ||
primaryKey = key; | ||
} else { | ||
return false; | ||
} | ||
} | ||
} | ||
if (isKeyup) { | ||
if (primaryKey != null) { | ||
primaryKey = primaryKey.toLowerCase(); | ||
} | ||
} else { | ||
if (isUpperCaseCharacter(primaryKey)) { | ||
modifiers.add('shift'); | ||
} | ||
if (modifiers.has('shift') && isLowerCaseCharacter(primaryKey)) { | ||
primaryKey = primaryKey.toUpperCase(); | ||
} | ||
} | ||
keystroke = []; | ||
if (!isKeyup || (isKeyup && (primaryKey == null))) { | ||
if (modifiers.has('ctrl')) { | ||
keystroke.push('ctrl'); | ||
} | ||
if (modifiers.has('alt')) { | ||
keystroke.push('alt'); | ||
} | ||
if (modifiers.has('shift')) { | ||
keystroke.push('shift'); | ||
} | ||
if (modifiers.has('cmd')) { | ||
keystroke.push('cmd'); | ||
} | ||
} | ||
if (primaryKey != null) { | ||
keystroke.push(primaryKey); | ||
} | ||
keystroke = keystroke.join('-'); | ||
if (isKeyup) { | ||
keystroke = "^" + keystroke; | ||
} | ||
return keystroke; | ||
}; | ||
parseKeystroke = function(keystroke) { | ||
var character, index, keyStart, keys, _i, _len; | ||
keys = []; | ||
keyStart = 0; | ||
for (index = _i = 0, _len = keystroke.length; _i < _len; index = ++_i) { | ||
character = keystroke[index]; | ||
if (character === '-') { | ||
if (index > keyStart) { | ||
keys.push(keystroke.substring(keyStart, index)); | ||
keyStart = index + 1; | ||
if (keyStart === keystroke.length) { | ||
return false; | ||
} | ||
} | ||
} | ||
} | ||
if (keyStart < keystroke.length) { | ||
keys.push(keystroke.substring(keyStart)); | ||
} | ||
return keys; | ||
}; | ||
exports.keystrokeForKeyboardEvent = function(event) { | ||
var altKey, characters, ctrlKey, isNonCharacterKey, key, keystroke, metaKey, nonAltModifiedKey, shiftKey, _ref; | ||
ctrlKey = event.ctrlKey, altKey = event.altKey, shiftKey = event.shiftKey, metaKey = event.metaKey; | ||
isNonCharacterKey = event.key.length > 1; | ||
if (isNonCharacterKey) { | ||
key = (_ref = NON_CHARACTER_KEY_NAMES_BY_KEYBOARD_EVENT_KEY[event.key]) != null ? _ref : event.key.toLowerCase(); | ||
} else { | ||
key = event.key; | ||
if (altKey) { | ||
if (process.platform === 'darwin') { | ||
if (event.code && (characters = KeyboardLayout.getCurrentKeymap()[event.code])) { | ||
if (shiftKey) { | ||
nonAltModifiedKey = characters.withShift; | ||
} else { | ||
nonAltModifiedKey = characters.unmodified; | ||
} | ||
if (!ctrlKey && !metaKey && isASCIICharacter(key) && key !== nonAltModifiedKey) { | ||
altKey = false; | ||
} else { | ||
key = nonAltModifiedKey; | ||
} | ||
} | ||
} else { | ||
if (event.getModifierState('AltGraph')) { | ||
altKey = false; | ||
} | ||
} | ||
} | ||
} | ||
if ((!isLatinCharacter(key) && (ctrlKey || altKey || metaKey)) || (metaKey && KeyboardLayout.getCurrentKeyboardLayout() === 'com.apple.keylayout.DVORAK-QWERTYCMD')) { | ||
if (characters = usCharactersForKeyCode(event.code)) { | ||
if (event.shiftKey) { | ||
key = characters.withShift; | ||
} else { | ||
key = characters.unmodified; | ||
} | ||
} | ||
} | ||
keystroke = ''; | ||
if (event.ctrlKey || key === 'Control') { | ||
if (key === 'ctrl' || ctrlKey) { | ||
keystroke += 'ctrl'; | ||
} | ||
if (event.altKey || key === 'Alt') { | ||
if (keystroke) { | ||
if (key === 'alt' || altKey) { | ||
if (keystroke.length > 0) { | ||
keystroke += '-'; | ||
@@ -180,11 +200,9 @@ } | ||
} | ||
if (event.shiftKey || key === 'Shift') { | ||
if (!/^[^A-Za-z]$/.test(key)) { | ||
if (keystroke) { | ||
keystroke += '-'; | ||
} | ||
keystroke += 'shift'; | ||
if (key === 'shift' || (shiftKey && (isNonCharacterKey || (isLatinCharacter(key) && isUpperCaseCharacter(key))))) { | ||
if (keystroke) { | ||
keystroke += '-'; | ||
} | ||
keystroke += 'shift'; | ||
} | ||
if (event.metaKey || key === 'Meta') { | ||
if (key === 'cmd' || metaKey) { | ||
if (keystroke) { | ||
@@ -195,3 +213,3 @@ keystroke += '-'; | ||
} | ||
if ((key != null) && !KeyboardEventModifiers.has(key)) { | ||
if (!MODIFIERS.has(key)) { | ||
if (keystroke) { | ||
@@ -208,10 +226,5 @@ keystroke += '-'; | ||
exports.characterForKeyboardEvent = function(event, dvorakQwertyWorkaroundEnabled) { | ||
var key; | ||
if (!(event.ctrlKey || event.altKey || event.metaKey)) { | ||
if (key = keyForKeyboardEvent(event, dvorakQwertyWorkaroundEnabled)) { | ||
if (key.length === 1) { | ||
return key; | ||
} | ||
} | ||
exports.characterForKeyboardEvent = function(event) { | ||
if (!(event.ctrlKey || event.metaKey)) { | ||
return event.key; | ||
} | ||
@@ -222,60 +235,32 @@ }; | ||
exports.isAtomModifier = function(keystroke) { | ||
return AtomModifiers.has(keystroke) || AtomModifierRegex.test(keystroke); | ||
exports.isBareModifier = function(keystroke) { | ||
return ENDS_IN_MODIFIER_REGEX.test(keystroke); | ||
}; | ||
exports.keydownEvent = function(key, options) { | ||
return keyboardEvent(key, 'keydown', options); | ||
return buildKeyboardEvent(key, 'keydown', options); | ||
}; | ||
exports.keyupEvent = function(key, options) { | ||
return keyboardEvent(key, 'keyup', options); | ||
return buildKeyboardEvent(key, 'keyup', options); | ||
}; | ||
keyboardEvent = function(key, eventType, _arg) { | ||
var alt, bubbles, cancelable, cmd, ctrl, event, keyCode, keyIdentifier, location, shift, target, view, _ref2; | ||
_ref2 = _arg != null ? _arg : {}, ctrl = _ref2.ctrl, shift = _ref2.shift, alt = _ref2.alt, cmd = _ref2.cmd, keyCode = _ref2.keyCode, target = _ref2.target, location = _ref2.location; | ||
event = document.createEvent('KeyboardEvent'); | ||
buildKeyboardEvent = function(key, eventType, _arg) { | ||
var alt, altKey, bubbles, cancelable, cmd, ctrl, ctrlKey, event, keyCode, location, metaKey, shift, shiftKey, target, _ref; | ||
_ref = _arg != null ? _arg : {}, ctrl = _ref.ctrl, shift = _ref.shift, alt = _ref.alt, cmd = _ref.cmd, keyCode = _ref.keyCode, target = _ref.target, location = _ref.location; | ||
ctrlKey = ctrl != null ? ctrl : false; | ||
altKey = alt != null ? alt : false; | ||
shiftKey = shift != null ? shift : false; | ||
metaKey = cmd != null ? cmd : false; | ||
bubbles = true; | ||
cancelable = true; | ||
view = null; | ||
if (LowerCaseLetterRegex.test(key)) { | ||
key = key.toUpperCase(); | ||
} | ||
if (key.length === 1) { | ||
keyIdentifier = "U+" + (key.charCodeAt(0).toString(16)); | ||
} else { | ||
switch (key) { | ||
case 'ctrl': | ||
keyIdentifier = 'Control'; | ||
if (eventType !== 'keyup') { | ||
ctrl = true; | ||
} | ||
break; | ||
case 'alt': | ||
keyIdentifier = 'Alt'; | ||
if (eventType !== 'keyup') { | ||
alt = true; | ||
} | ||
break; | ||
case 'shift': | ||
keyIdentifier = 'Shift'; | ||
if (eventType !== 'keyup') { | ||
shift = true; | ||
} | ||
break; | ||
case 'cmd': | ||
keyIdentifier = 'Meta'; | ||
if (eventType !== 'keyup') { | ||
cmd = true; | ||
} | ||
break; | ||
default: | ||
keyIdentifier = key[0].toUpperCase() + key.slice(1); | ||
} | ||
} | ||
if (location == null) { | ||
location = KeyboardEvent.DOM_KEY_LOCATION_STANDARD; | ||
} | ||
event.initKeyboardEvent(eventType, bubbles, cancelable, view, keyIdentifier, location, ctrl, alt, shift, cmd); | ||
event = new KeyboardEvent(eventType, { | ||
key: key, | ||
ctrlKey: ctrlKey, | ||
altKey: altKey, | ||
shiftKey: shiftKey, | ||
metaKey: metaKey, | ||
bubbles: bubbles, | ||
cancelable: cancelable | ||
}); | ||
if (target != null) { | ||
@@ -293,12 +278,2 @@ Object.defineProperty(event, 'target', { | ||
} | ||
Object.defineProperty(event, 'keyCode', { | ||
get: function() { | ||
return keyCode; | ||
} | ||
}); | ||
Object.defineProperty(event, 'which', { | ||
get: function() { | ||
return keyCode; | ||
} | ||
}); | ||
return event; | ||
@@ -308,3 +283,3 @@ }; | ||
exports.keystrokesMatch = function(bindingKeystrokes, userKeystrokes) { | ||
var bindingKeystroke, bindingKeystrokeIndex, bindingRemainderContainsOnlyKeyups, doesMatch, isPartialMatch, matchesNextUserKeystroke, userKeystrokeIndex, userKeystrokesHasKeydownEvent, _k, _len2; | ||
var bindingKeystroke, bindingKeystrokeIndex, bindingRemainderContainsOnlyKeyups, doesMatch, isPartialMatch, matchesNextUserKeystroke, userKeystrokeIndex, userKeystrokesHasKeydownEvent, _i, _len; | ||
userKeystrokeIndex = -1; | ||
@@ -332,4 +307,4 @@ userKeystrokesHasKeydownEvent = false; | ||
bindingKeystrokeIndex = 0; | ||
for (_k = 0, _len2 = bindingKeystrokes.length; _k < _len2; _k++) { | ||
bindingKeystroke = bindingKeystrokes[_k]; | ||
for (_i = 0, _len = bindingKeystrokes.length; _i < _len; _i++) { | ||
bindingKeystroke = bindingKeystrokes[_i]; | ||
if (!isPartialMatch) { | ||
@@ -357,187 +332,10 @@ doesMatch = matchesNextUserKeystroke(bindingKeystroke); | ||
if (isPartialMatch && bindingRemainderContainsOnlyKeyups) { | ||
return KeydownExactMatch; | ||
return MATCH_TYPES.KEYDOWN_EXACT; | ||
} else if (isPartialMatch) { | ||
return PartialMatch; | ||
return MATCH_TYPES.PARTIAL; | ||
} else { | ||
return ExactMatch; | ||
return MATCH_TYPES.EXACT; | ||
} | ||
}; | ||
normalizeKeystroke = function(keystroke) { | ||
var i, isKeyup, key, keys, modifiers, primaryKey, _k, _len2; | ||
if (isKeyup = keystroke.startsWith('^')) { | ||
keystroke = keystroke.slice(1); | ||
} | ||
keys = parseKeystroke(keystroke); | ||
if (!keys) { | ||
return false; | ||
} | ||
primaryKey = null; | ||
modifiers = new Set; | ||
for (i = _k = 0, _len2 = keys.length; _k < _len2; i = ++_k) { | ||
key = keys[i]; | ||
if (AtomModifiers.has(key)) { | ||
modifiers.add(key); | ||
} else { | ||
if (i === keys.length - 1) { | ||
primaryKey = key; | ||
} else { | ||
return false; | ||
} | ||
} | ||
} | ||
if (isKeyup) { | ||
if (primaryKey != null) { | ||
primaryKey = primaryKey.toLowerCase(); | ||
} | ||
} else { | ||
if (UpperCaseLetterRegex.test(primaryKey)) { | ||
modifiers.add('shift'); | ||
} | ||
if (modifiers.has('shift') && LowerCaseLetterRegex.test(primaryKey)) { | ||
primaryKey = primaryKey.toUpperCase(); | ||
} | ||
} | ||
keystroke = []; | ||
if (!isKeyup || (isKeyup && (primaryKey == null))) { | ||
if (modifiers.has('ctrl')) { | ||
keystroke.push('ctrl'); | ||
} | ||
if (modifiers.has('alt')) { | ||
keystroke.push('alt'); | ||
} | ||
if (modifiers.has('shift')) { | ||
keystroke.push('shift'); | ||
} | ||
if (modifiers.has('cmd')) { | ||
keystroke.push('cmd'); | ||
} | ||
} | ||
if (primaryKey != null) { | ||
keystroke.push(primaryKey); | ||
} | ||
keystroke = keystroke.join('-'); | ||
if (isKeyup) { | ||
keystroke = "^" + keystroke; | ||
} | ||
return keystroke; | ||
}; | ||
parseKeystroke = function(keystroke) { | ||
var character, index, keyStart, keys, _k, _len2; | ||
keys = []; | ||
keyStart = 0; | ||
for (index = _k = 0, _len2 = keystroke.length; _k < _len2; index = ++_k) { | ||
character = keystroke[index]; | ||
if (character === '-') { | ||
if (index > keyStart) { | ||
keys.push(keystroke.substring(keyStart, index)); | ||
keyStart = index + 1; | ||
if (keyStart === keystroke.length) { | ||
return false; | ||
} | ||
} | ||
} | ||
} | ||
if (keyStart < keystroke.length) { | ||
keys.push(keystroke.substring(keyStart)); | ||
} | ||
return keys; | ||
}; | ||
keyForKeyboardEvent = function(event, dvorakQwertyWorkaroundEnabled) { | ||
var charCode, key, keyIdentifier, _ref2, _ref3; | ||
keyIdentifier = event.keyIdentifier; | ||
if ((_ref2 = process.platform) === 'linux' || _ref2 === 'win32') { | ||
keyIdentifier = translateKeyIdentifierForWindowsAndLinuxChromiumBug(keyIdentifier); | ||
} | ||
if (KeyboardEventModifiers.has(keyIdentifier)) { | ||
return keyIdentifier; | ||
} | ||
charCode = charCodeFromKeyIdentifier(keyIdentifier); | ||
if (dvorakQwertyWorkaroundEnabled && typeof charCode === 'number') { | ||
if (event.keyCode === 46) { | ||
charCode = 127; | ||
} else { | ||
charCode = event.keyCode; | ||
} | ||
} | ||
if (charCode != null) { | ||
if ((_ref3 = process.platform) === 'linux' || _ref3 === 'win32') { | ||
charCode = translateCharCodeForWindowsAndLinuxChromiumBug(charCode, event.shiftKey); | ||
} | ||
if (event.location === KeyboardEvent.DOM_KEY_LOCATION_NUMPAD) { | ||
charCode = numpadToASCII(charCode); | ||
} | ||
if (!isASCII(charCode) && isASCII(event.keyCode)) { | ||
charCode = event.which; | ||
} | ||
key = keyFromCharCode(charCode); | ||
} else { | ||
key = keyIdentifier.toLowerCase(); | ||
} | ||
if (event.shiftKey) { | ||
if (LowerCaseLetterRegex.test(key)) { | ||
key = key.toUpperCase(); | ||
} | ||
} else { | ||
if (UpperCaseLetterRegex.test(key)) { | ||
key = key.toLowerCase(); | ||
} | ||
} | ||
return key; | ||
}; | ||
charCodeFromKeyIdentifier = function(keyIdentifier) { | ||
if (keyIdentifier.indexOf('U+') === 0) { | ||
return parseInt(keyIdentifier.slice(2), 16); | ||
} | ||
}; | ||
translateKeyIdentifierForWindowsAndLinuxChromiumBug = function(keyIdentifier) { | ||
var _ref2; | ||
return (_ref2 = WindowsAndLinuxKeyIdentifierTranslations[keyIdentifier]) != null ? _ref2 : keyIdentifier; | ||
}; | ||
translateCharCodeForWindowsAndLinuxChromiumBug = function(charCode, shift) { | ||
var translation; | ||
if (translation = WindowsAndLinuxCharCodeTranslations[charCode]) { | ||
if (shift) { | ||
return translation.shifted; | ||
} else { | ||
return translation.unshifted; | ||
} | ||
} else { | ||
return charCode; | ||
} | ||
}; | ||
keyFromCharCode = function(charCode) { | ||
switch (charCode) { | ||
case 8: | ||
return 'backspace'; | ||
case 9: | ||
return 'tab'; | ||
case 13: | ||
return 'enter'; | ||
case 27: | ||
return 'escape'; | ||
case 32: | ||
return 'space'; | ||
case 127: | ||
return 'delete'; | ||
default: | ||
return String.fromCharCode(charCode); | ||
} | ||
}; | ||
isASCII = function(charCode) { | ||
return (0 <= charCode && charCode <= 127); | ||
}; | ||
numpadToASCII = function(charCode) { | ||
var _ref2; | ||
return (_ref2 = NumPadToASCII[charCode]) != null ? _ref2 : charCode; | ||
}; | ||
}).call(this); |
(function() { | ||
var CSON, CommandEvent, CompositeDisposable, Disposable, Emitter, File, KeyBinding, KeymapManager, OtherPlatforms, Platforms, characterForKeyboardEvent, fs, isAtomModifier, isSelectorValid, keydownEvent, keystrokeForKeyboardEvent, keystrokesMatch, keyupEvent, normalizeKeystrokes, observeCurrentKeyboardLayout, path, _ref, _ref1, | ||
var CSON, CommandEvent, CompositeDisposable, Disposable, Emitter, File, KeyBinding, KeymapManager, OtherPlatforms, Platforms, characterForKeyboardEvent, fs, isBareModifier, isSelectorValid, keydownEvent, keystrokeForKeyboardEvent, keystrokesMatch, keyupEvent, normalizeKeystrokes, observeCurrentKeyboardLayout, path, _ref, _ref1, | ||
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; | ||
@@ -23,3 +23,3 @@ | ||
_ref1 = require('./helpers'), normalizeKeystrokes = _ref1.normalizeKeystrokes, keystrokeForKeyboardEvent = _ref1.keystrokeForKeyboardEvent, isAtomModifier = _ref1.isAtomModifier, keydownEvent = _ref1.keydownEvent, keyupEvent = _ref1.keyupEvent, characterForKeyboardEvent = _ref1.characterForKeyboardEvent, keystrokesMatch = _ref1.keystrokesMatch; | ||
_ref1 = require('./helpers'), normalizeKeystrokes = _ref1.normalizeKeystrokes, keystrokeForKeyboardEvent = _ref1.keystrokeForKeyboardEvent, isBareModifier = _ref1.isBareModifier, keydownEvent = _ref1.keydownEvent, keyupEvent = _ref1.keyupEvent, characterForKeyboardEvent = _ref1.characterForKeyboardEvent, keystrokesMatch = _ref1.keystrokesMatch; | ||
@@ -329,3 +329,3 @@ Platforms = ['darwin', 'freebsd', 'linux', 'sunos', 'win32']; | ||
keystroke = this.keystrokeForKeyboardEvent(event); | ||
if (event.type === 'keydown' && this.queuedKeystrokes.length > 0 && isAtomModifier(keystroke)) { | ||
if (event.type === 'keydown' && this.queuedKeystrokes.length > 0 && isBareModifier(keystroke)) { | ||
event.preventDefault(); | ||
@@ -332,0 +332,0 @@ return; |
{ | ||
"name": "atom-keymap", | ||
"version": "6.3.2", | ||
"version": "6.3.3-beta0", | ||
"description": "Atom's DOM-aware keymap module", | ||
"main": "./lib/keymap-manager", | ||
"scripts": { | ||
"prepublish": "grunt prepublish", | ||
"test": "grunt test", | ||
"benchmark": "coffee --nodejs --harmony_collections benchmark/benchmark.coffee" | ||
"prepublish": "npm run clean && npm run compile && npm run lint && npm run atomdoc", | ||
"clean": "rimraf lib && rimraf api.json", | ||
"compile": "coffee --no-header --output lib --compile src && babel src --out-dir lib", | ||
"lint": "coffeelint -r src spec && eslint src spec", | ||
"test": "devtool --quit --console node_modules/mocha/bin/_mocha --colors spec/helpers/setup.js spec/*", | ||
"test-drive": "SUPPRESS_EXIT=true devtool --quit node_modules/mocha/bin/_mocha --no-colors spec/helpers/setup.js spec/*", | ||
"ci": "npm run compile && npm run lint && npm run test", | ||
"atomdoc": "grunt shell:update-atomdoc atomdoc" | ||
}, | ||
@@ -25,3 +30,3 @@ "repository": { | ||
"grim": "^1.2.1", | ||
"keyboard-layout": "^1.0", | ||
"keyboard-layout": "^1.1.0", | ||
"pathwatcher": "^6.2", | ||
@@ -32,15 +37,42 @@ "property-accessors": "^1", | ||
"devDependencies": { | ||
"coffee-script": "^1.7.0", | ||
"jasmine-focused": "^1.0.4", | ||
"grunt-contrib-coffee": "^0.9.0", | ||
"grunt-cli": "^0.1.8", | ||
"grunt": "^0.4.1", | ||
"grunt-shell": "^0.2.2", | ||
"grunt-coffeelint": "^0.0.6", | ||
"rimraf": "^2.2.2", | ||
"coffee-cache": "^0.2.0", | ||
"temp": "^0.6.0", | ||
"space-pencil": "^0.3.0", | ||
"grunt-atomdoc": "^1.0.0" | ||
"babel-cli": "6.5.1", | ||
"babel-eslint": "5.0.0-beta10", | ||
"babel-preset-es2015": "6.5.0", | ||
"babel-preset-stage-0": "6.5.0", | ||
"babel-register": "6.5.2", | ||
"chai": "3.5.0", | ||
"coffee-cache": "0.2.0", | ||
"coffee-script": "1.7.0", | ||
"coffeelint": "1.14.2", | ||
"debounce": "1.0.0", | ||
"devtool": "2.2.0", | ||
"electron-rebuild": "1.2.1", | ||
"eslint": "2.2.0", | ||
"eslint-config-standard": "5.1.0", | ||
"eslint-plugin-promise": "1.0.8", | ||
"eslint-plugin-standard": "1.3.1", | ||
"grunt": "0.4.1", | ||
"grunt-atomdoc": "1.0.0", | ||
"grunt-cli": "0.1.8", | ||
"grunt-coffeelint": "0.0.6", | ||
"grunt-contrib-coffee": "0.9.0", | ||
"grunt-shell": "0.2.2", | ||
"lolex": "1.4.0", | ||
"mocha": "2.4.5", | ||
"rimraf": "2.2.2", | ||
"sinon": "1.17.3", | ||
"space-pencil": "0.3.0", | ||
"temp": "0.8.3" | ||
}, | ||
"coffeelintConfig": { | ||
"no_empty_param_list": { | ||
"level": "error" | ||
}, | ||
"max_line_length": { | ||
"level": "ignore" | ||
}, | ||
"indentation": { | ||
"level": "ignore" | ||
} | ||
} | ||
} |
@@ -31,1 +31,10 @@ # atom-keymap [![Build Status](https://travis-ci.org/atom/atom-keymap.svg?branch=master)](https://travis-ci.org/atom/atom-keymap) | ||
``` | ||
## Development | ||
The tests for this module *must* be run in Electron because they depend on browser APIs. | ||
* [`devtool`](https://github.com/Jam3/devtool) is bundled as a development dependency to run the tests. | ||
* Native modules need to be compiled against the version of Electron included with `devtool`. **Be sure to run `electron-rebuild` be sure recompile native dependencies before running tests.** | ||
* Tests can be run in batch mode with `npm test` | ||
* If you want to use the debugger, profiler, etc or just speed up your flow by being able to refresh the `devtool` window to re-run tests, use the `npm run test-drive` script. This will keep `devtool` open instead of exiting after the test run. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
71139
9
1729
40
28
2
Updatedkeyboard-layout@^1.1.0