Reload user keymap when it is moved/removed

This commit is contained in:
Kevin Sawicki
2014-01-17 14:08:30 -08:00
parent ba1303a895
commit 8436e8f62e
2 changed files with 21 additions and 9 deletions

View File

@@ -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()

View File

@@ -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'])