mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
Move disabledKeymaps observer into package manager
This commit is contained in:
@@ -455,6 +455,7 @@ describe "PackageManager", ->
|
||||
describe "when the package's keymaps are disabled and re-enabled after it is activated", ->
|
||||
it "removes and re-adds the keymaps", ->
|
||||
element1 = $$ -> @div class: 'test-1'
|
||||
atom.packages.observeDisabledKeymaps()
|
||||
|
||||
waitsForPromise ->
|
||||
atom.packages.activatePackage("package-with-keymaps-manifest")
|
||||
|
||||
@@ -310,6 +310,19 @@ class PackageManager
|
||||
@activatePackage(packageName) for packageName in packagesToEnable
|
||||
null
|
||||
|
||||
unobserveDisabledKeymaps: ->
|
||||
@disabledKeymapsSubscription?.dispose()
|
||||
@disabledKeymapsSubscription = null
|
||||
|
||||
observeDisabledKeymaps: ->
|
||||
@disabledKeymapsSubscription ?= atom.config.onDidChange 'core.disabledKeymaps', ({newValue, oldValue}) =>
|
||||
keymapsToEnable = _.difference(oldValue, newValue)
|
||||
keymapsToDisable = _.difference(newValue, oldValue)
|
||||
|
||||
@getLoadedPackage(packageName).deactivateKeymaps() for packageName in keymapsToDisable when not @isPackageDisabled(packageName)
|
||||
@getLoadedPackage(packageName).activateKeymaps() for packageName in keymapsToEnable when not @isPackageDisabled(packageName)
|
||||
null
|
||||
|
||||
loadPackages: ->
|
||||
# Ensure atom exports is already in the require cache so the load time
|
||||
# of the first package isn't skewed by being the first to require atom
|
||||
@@ -396,6 +409,7 @@ class PackageManager
|
||||
promises.push(promise) unless pack.hasActivationCommands()
|
||||
return
|
||||
@observeDisabledPackages()
|
||||
@observeDisabledKeymaps()
|
||||
promises
|
||||
|
||||
# Activate a single package by name
|
||||
@@ -424,6 +438,7 @@ class PackageManager
|
||||
@deactivatePackage(pack.name) for pack in @getLoadedPackages()
|
||||
return
|
||||
@unobserveDisabledPackages()
|
||||
@unobserveDisabledKeymaps()
|
||||
|
||||
# Deactivate the package with the given name
|
||||
deactivatePackage: (name) ->
|
||||
|
||||
@@ -201,12 +201,11 @@ class Package
|
||||
activateResources: ->
|
||||
@activationDisposables = new CompositeDisposable
|
||||
|
||||
@activationDisposables.add atom.config.observe "core.disabledKeymaps", {}, (map) =>
|
||||
value = not _.include(map ? [], @name)
|
||||
if value
|
||||
@activateKeymaps()
|
||||
else if not value
|
||||
@deactivateKeymaps()
|
||||
value = not _.include(atom.config.get("core.disabledKeymaps") ? [], @name)
|
||||
if value
|
||||
@activateKeymaps()
|
||||
else if not value
|
||||
@deactivateKeymaps()
|
||||
|
||||
for [menuPath, map] in @menus when map['context-menu']?
|
||||
try
|
||||
@@ -260,7 +259,7 @@ class Package
|
||||
for [path, map] in @keymaps
|
||||
if map.length > 0
|
||||
return true
|
||||
|
||||
|
||||
false
|
||||
|
||||
activateServices: ->
|
||||
|
||||
Reference in New Issue
Block a user