mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-02-01 12:58:52 +08:00
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:
parent
bdfd96fed2
commit
386a599fbc
2 changed files with 8 additions and 12 deletions
|
@ -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()
|
||||
|
|
|
@ -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}">
|
||||
|
|
Loading…
Reference in a new issue