diff --git a/spec/keymap-spec.coffee b/spec/keymap-spec.coffee index 0e659be11..d976144ed 100644 --- a/spec/keymap-spec.coffee +++ b/spec/keymap-spec.coffee @@ -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() diff --git a/src/keymap.coffee b/src/keymap.coffee index e654fc9a5..e75faf17d 100644 --- a/src/keymap.coffee +++ b/src/keymap.coffee @@ -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'])