fix(keymaps): Listen to atom commands instead of DOM events

Using `addEventListener` only works when the command is triggered by the atom keymaps manager, NOT when the command is triggered by the command registry (NylasEnv.commands.dispatch). Odds are, when you subscribe to key commands you /really/ mean to subscribe to the command, no matter how it's invoked.

This fixes #556, in which the down / up arrows in the message list weren't working.
This commit is contained in:
Ben Gotow 2015-12-04 18:26:26 -08:00
parent 931a93af4e
commit 5b9f368b7a
2 changed files with 8 additions and 12 deletions

View file

@ -150,6 +150,7 @@ DownButton = React.createClass
_onClick: ->
return if @state.disabled
NylasEnv.commands.dispatch(document.body, 'core:next-item')
return
_getStateFromStores: ->
disabled: @isLastThread()
@ -173,6 +174,7 @@ UpButton = React.createClass
_onClick: ->
return if @state.disabled
NylasEnv.commands.dispatch(document.body, 'core:previous-item')
return
_getStateFromStores: ->
disabled: @isFirstThread()

View file

@ -113,22 +113,16 @@ class KeyCommandsRegion extends React.Component
# particular scope, we simply need to listen at the root window level
# here for all commands coming in.
_setupListeners: (props) ->
_.each props.globalHandlers, (callback, handler) ->
window.addEventListener(handler, callback)
@_globalDisposable = NylasEnv.commands.add('body', props.globalHandlers)
return unless @_mounted
$el = React.findDOMNode(@)
_.each props.localHandlers, (callback, handler) ->
$el.addEventListener(handler, callback)
@_localDisposable = NylasEnv.commands.add($el, props.localHandlers)
_unmountListeners: ->
_.each @props.globalHandlers, (callback, handler) ->
window.removeEventListener(handler, callback)
return unless @_mounted
$el = React.findDOMNode(@)
_.each @props.localHandlers, (callback, handler) ->
$el.removeEventListener(handler, callback)
@_globalDisposable?.dispose()
@_globalDisposable = null
@_localDisposable?.dispose()
@_localDisposable = null
render: ->
<div className="key-commands-region #{@props.className}">