Add rootView.activeKeybindings().

This will return all active keybindings available for the focused element.
This commit is contained in:
Corey Johnson
2012-05-29 14:27:22 -07:00
parent 64bd26a392
commit 893564945e
4 changed files with 31 additions and 3 deletions

View File

@@ -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"
expect(bindings['g']).toEqual "command-and-grandchild-node"

View File

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

View File

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

View File

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