fix(keymaps): Small tweaks to fix broken key behaviors

- Reload the menu after changing keymap sets
- Do not allow accelerators in the menu like "z", because they do not go through selector-based command matching and always fire into the window.
- Do not match `cmdctrl` to both `cmd` and `ctrl` on the Mac. Just `cmd`
- Re-order `shift-delete` mapping to `core:cut`, because it causes the menu to have no binding on Mac OS X
This commit is contained in:
Ben Gotow 2015-11-13 16:05:40 -08:00
parent 41e3b01240
commit 2e618d40a6
5 changed files with 24 additions and 31 deletions

View file

@ -23,11 +23,11 @@
'cmdctrl-z': 'core:undo' 'cmdctrl-z': 'core:undo'
'cmdctrl-Z': 'core:redo' 'cmdctrl-Z': 'core:redo'
'cmdctrl-y': 'core:redo' 'cmdctrl-y': 'core:redo'
'shift-delete': 'core:cut'
'cmdctrl-x': 'core:cut' 'cmdctrl-x': 'core:cut'
'cmdctrl-c': 'core:copy' 'cmdctrl-c': 'core:copy'
'cmdctrl-v': 'core:paste' 'cmdctrl-v': 'core:paste'
'cmdctrl-a': 'core:select-all' 'cmdctrl-a': 'core:select-all'
'shift-delete': 'core:cut'
'up' : 'core:previous-item' 'up' : 'core:previous-item'
'down' : 'core:next-item' 'down' : 'core:next-item'

View file

@ -4,13 +4,13 @@
'body': 'body':
# Windows email-specific menu items # Windows email-specific menu items
'cmdctrl-shift-v': 'application:change-category' # Outlook 'cmdctrl-shift-v': 'application:change-category' # Outlook
'F3': 'application:focus-search' 'F3': 'application:focus-search'
'cmdctrl-e': 'application:focus-search' 'cmdctrl-e': 'application:focus-search'
'cmdctrl-f': 'application:forward' 'cmdctrl-f': 'application:forward'
'cmdctrl-shift-v': 'application:change-category' 'cmdctrl-shift-v': 'application:change-category'
'cmdctrl-d': 'application:delete-item' 'cmdctrl-d': 'application:delete-item'
'alt-backspace':'core:undo' 'alt-backspace': 'core:undo'
'alt-s': 'application:send-message' 'alt-s': 'application:send-message'
'cmdctrl-r': 'application:reply' 'cmdctrl-r': 'application:reply'
'cmdctrl-shift-r': 'application:reply-all' 'cmdctrl-shift-r': 'application:reply-all'
'cmdctrl-n' : 'application:new-message' 'cmdctrl-n' : 'application:new-message'

View file

@ -415,23 +415,19 @@ class Application
sendCommand: (command, args...) -> sendCommand: (command, args...) ->
unless @emit(command, args...) unless @emit(command, args...)
focusedWindow = @windowManager.focusedWindow() focusedWindow = @windowManager.focusedWindow()
focusedBrowserWindow = BrowserWindow.getFocusedWindow() if focusedWindow
mainWindow = @windowManager.mainWindow()
if focusedWindow?
focusedWindow.sendCommand(command, args...) focusedWindow.sendCommand(command, args...)
else if focusedBrowserWindow?
# Note: We sometimes display non-"AtomWindow" windows, for things like
# raw message contents. Ensure that these also get to run window commands
unless @sendCommandToFirstResponder(command)
switch command
when 'window:reload' then focusedBrowserWindow.reload()
when 'window:toggle-dev-tools' then focusedBrowserWindow.toggleDevTools()
when 'window:close' then focusedBrowserWindow.close()
else if mainWindow?
mainWindow.sendCommand(command, args...)
else else
@sendCommandToFirstResponder(command) unless @sendCommandToFirstResponder(command)
focusedBrowserWindow = BrowserWindow.getFocusedWindow()
mainWindow = @windowManager.mainWindow()
if focusedBrowserWindow
switch command
when 'window:reload' then focusedBrowserWindow.reload()
when 'window:toggle-dev-tools' then focusedBrowserWindow.toggleDevTools()
when 'window:close' then focusedBrowserWindow.close()
else if mainWindow
mainWindow.sendCommand(command, args...)
# Public: Executes the given command on the given window. # Public: Executes the given command on the given window.
# #

View file

@ -1,20 +1,16 @@
KeymapUtils = KeymapUtils =
cmdCtrlPreprocessor: (keymap={}) -> cmdCtrlPreprocessor: (keymap={}) ->
re = /(cmdctrl|ctrlcmd)/i re = /(cmdctrl|ctrlcmd)/i
if process.platform is "darwin"
cmdctrl = 'cmd'
else
cmdctrl = 'ctrl'
for selector, keyBindings of keymap for selector, keyBindings of keymap
normalizedBindings = {} normalizedBindings = {}
for keystrokes, command of keyBindings for keystrokes, command of keyBindings
if re.test keystrokes keystrokes = keystrokes.replace(re, cmdctrl)
if process.platform is "darwin" normalizedBindings[keystrokes] = command
newKeystrokes1= keystrokes.replace(re, "ctrl")
newKeystrokes2= keystrokes.replace(re, "cmd")
normalizedBindings[newKeystrokes1] = command
normalizedBindings[newKeystrokes2] = command
else
newKeystrokes = keystrokes.replace(re, "ctrl")
normalizedBindings[newKeystrokes] = command
else
normalizedBindings[keystrokes] = command
keymap[selector] = normalizedBindings keymap[selector] = normalizedBindings
return keymap return keymap

View file

@ -64,6 +64,7 @@ class MenuManager
@pendingUpdateOperation = null @pendingUpdateOperation = null
@template = [] @template = []
atom.keymaps.onDidLoadBundledKeymaps => @loadPlatformItems() atom.keymaps.onDidLoadBundledKeymaps => @loadPlatformItems()
atom.keymaps.onDidReloadKeymap => @update()
atom.packages.onDidActivateInitialPackages => @sortPackagesMenu() atom.packages.onDidActivateInitialPackages => @sortPackagesMenu()
# Public: Adds the given items to the application menu. # Public: Adds the given items to the application menu.
@ -165,7 +166,7 @@ class MenuManager
for key, bindings of keystrokesByCommand for key, bindings of keystrokesByCommand
for binding in bindings for binding in bindings
continue if binding.indexOf(' ') != -1 continue if binding.indexOf(' ') != -1
continue unless /(cmd|ctrl|shift|alt)/.test(binding)
filtered[key] ?= [] filtered[key] ?= []
filtered[key].push(binding) filtered[key].push(binding)
filtered filtered