mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
Add rootView.activeKeybindings().
This will return all active keybindings available for the focused element.
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user