mirror of
https://github.com/atom/atom.git
synced 2026-01-22 13:28:01 -05:00
Reload user keymap when it is moved/removed
This commit is contained in:
@@ -369,3 +369,12 @@ describe "Keymap", ->
|
||||
runs ->
|
||||
keyBinding = keymap.keyBindingsForKeystroke('ctrl-l')[0]
|
||||
expect(keyBinding.command).toBe 'core:move-right'
|
||||
keymap.loadUserKeymap.reset()
|
||||
fs.removeSync(keymapFilePath)
|
||||
|
||||
waitsFor ->
|
||||
keymap.loadUserKeymap.callCount > 0
|
||||
|
||||
runs ->
|
||||
keyBinding = keymap.keyBindingsForKeystroke('ctrl-l')[0]
|
||||
expect(keyBinding).toBeUndefined()
|
||||
|
||||
@@ -122,21 +122,24 @@ class Keymap
|
||||
@loadDirectory(path.join(@resourcePath, 'keymaps'))
|
||||
@emit('bundled-keymaps-loaded')
|
||||
|
||||
userKeymapPath: ->
|
||||
CSON.resolve(path.join(@configDirPath, 'keymap'))
|
||||
getUserKeymapPath: ->
|
||||
if userKeymapPath = CSON.resolve(path.join(@configDirPath, 'keymap'))
|
||||
userKeymapPath
|
||||
else
|
||||
path.join(@configDirPath, 'keymap.cson')
|
||||
|
||||
unwatchUserKeymap: ->
|
||||
keymapPath = @userKeymapPath()
|
||||
@userKeymapFile?.off()
|
||||
@remove(keymapPath) if keymapPath
|
||||
@remove(@userKeymapPath) if @userKeymapPath?
|
||||
|
||||
loadUserKeymap: ->
|
||||
keymapPath = @userKeymapPath()
|
||||
@unwatchUserKeymap()
|
||||
if keymapPath
|
||||
@load(keymapPath)
|
||||
@userKeymapFile = new File(keymapPath)
|
||||
@userKeymapFile.on 'contents-changed', => @loadUserKeymap()
|
||||
userKeymapPath = @getUserKeymapPath()
|
||||
if fs.isFileSync(userKeymapPath)
|
||||
@userKeymapPath = userKeymapPath
|
||||
@load(userKeymapPath)
|
||||
@userKeymapFile = new File(userKeymapPath)
|
||||
@userKeymapFile.on 'contents-changed moved removed', => @loadUserKeymap()
|
||||
|
||||
loadDirectory: (directoryPath) ->
|
||||
@load(filePath) for filePath in fs.listSync(directoryPath, ['.cson', '.json'])
|
||||
|
||||
Reference in New Issue
Block a user