Don't register CommandRegistry's window listeners in AtomEnvironment constructor

This commit is contained in:
Max Brunsfeld
2015-10-08 17:34:41 -07:00
parent 04c85e3aae
commit 5c545c0898
4 changed files with 29 additions and 4 deletions

View File

@@ -589,6 +589,8 @@ class AtomEnvironment extends Model
@setAutoHideMenuBar(newValue)
@setAutoHideMenuBar(true) if @config.get('core.autoHideMenuBar')
@commands.attach(window)
@openInitialEmptyEditorIfNecessary()
unloadEditorWindow: ->

View File

@@ -44,7 +44,8 @@ SequenceCount = 0
# ```
module.exports =
class CommandRegistry
constructor: (@rootNode) ->
constructor: ->
@rootNode = null
@clear()
clear: ->
@@ -53,9 +54,13 @@ class CommandRegistry
@inlineListenersByCommandName = {}
@emitter = new Emitter
attach: (@rootNode) ->
@commandRegistered(command) for command of @selectorBasedListenersByCommandName
@commandRegistered(command) for command of @inlineListenersByCommandName
destroy: ->
for commandName of @registeredCommands
window.removeEventListener(commandName, @handleCommandEvent, true)
@rootNode.removeEventListener(commandName, @handleCommandEvent, true)
return
# Public: Add one or more command listeners associated with a selector.
@@ -256,8 +261,8 @@ class CommandRegistry
matched
commandRegistered: (commandName) ->
unless @registeredCommands[commandName]
window.addEventListener(commandName, @handleCommandEvent, true)
if @rootNode? and not @registeredCommands[commandName]
@rootNode.addEventListener(commandName, @handleCommandEvent, true)
@registeredCommands[commandName] = true
class SelectorBasedListener