diff --git a/spec/app/keymap-spec.coffee b/spec/app/keymap-spec.coffee index b341debd4..5199c9509 100644 --- a/spec/app/keymap-spec.coffee +++ b/spec/app/keymap-spec.coffee @@ -225,11 +225,11 @@ describe "Keymap", -> expect(bindings['g']).toEqual "g" describe "when multiple bindings match a keystroke", -> - fit "only returns bindings that match the most specific selector", -> + it "only returns bindings that match the most specific selector", -> keymap.bindKeys '.command-mode', 'g': 'command-mode' keymap.bindKeys '.command-mode .grandchild-node', 'g': 'command-and-grandchild-node' keymap.bindKeys '.grandchild-node', 'g': 'grandchild-node' bindings = keymap.bindingsForElement(fragment.find('.grandchild-node')) expect(Object.keys(bindings).length).toBe 1 - expect(bindings['g']).toEqual "command-and-grandchild-node" \ No newline at end of file + expect(bindings['g']).toEqual "command-and-grandchild-node" diff --git a/spec/app/root-view-spec.coffee b/spec/app/root-view-spec.coffee index 46cd37506..e3a1f401f 100644 --- a/spec/app/root-view-spec.coffee +++ b/spec/app/root-view-spec.coffee @@ -356,6 +356,32 @@ describe "RootView", -> rootView.trigger(event) expect(commandHandler).toHaveBeenCalled() + describe ".activeKeybindings()", -> + originalKeymap = null + keymap = null + editor = null + + beforeEach -> + rootView.attachToDom() + editor = rootView.activeEditor() + keymap = new (require 'keymap') + originalKeymap = window.keymap + window.keymap = keymap + + afterEach -> + window.keymap = originalKeymap + + it "returns all keybindings available for focused element", -> + editor.on 'test-event-a', => # nothing + + keymap.bindKeys ".editor", + "meta-a": "test-event-a" + "meta-b": "test-event-b" + + keybindings = rootView.activeKeybindings() + expect(Object.keys(keybindings).length).toBe 2 + expect(keybindings["meta-a"]).toEqual "test-event-a" + describe "when the path of the focused editor's buffer changes", -> it "changes the document.title and emits an active-editor-path-change event", -> pathChangeHandler = jasmine.createSpy 'pathChangeHandler' diff --git a/src/app/keymap.coffee b/src/app/keymap.coffee index d729083a0..75778a40e 100644 --- a/src/app/keymap.coffee +++ b/src/app/keymap.coffee @@ -32,7 +32,6 @@ class Keymap while currentNode.length bindingSets = @bindingSets.filter (set) -> currentNode.is(set.selector) - console.log @bindingSets, currentNode bindingSets.sort (a, b) -> b.specificity - a.specificity for bindingSet in bindingSets diff --git a/src/app/root-view.coffee b/src/app/root-view.coffee index 0109e3391..34aaa5113 100644 --- a/src/app/root-view.coffee +++ b/src/app/root-view.coffee @@ -114,6 +114,9 @@ class RootView extends View if not previousActiveEditor or editor.buffer.path != previousActiveEditor.buffer.path @trigger 'active-editor-path-change', editor.buffer.path + activeKeybindings: -> + keymap.bindingsForElement(document.activeElement) + setTitle: (title='untitled') -> document.title = title