Merge branch 'master' into structural-folding

This commit is contained in:
Corey Johnson
2012-05-31 16:24:01 -07:00
13 changed files with 147 additions and 53 deletions

View File

@@ -190,18 +190,6 @@ describe "Keymap", ->
expect(fooHandler).toHaveBeenCalled()
describe ".bindKey(selector, pattern, eventName)", ->
it "binds a single key", ->
keymap.bindKey '.child-node', 'z', 'foo'
fooHandler = jasmine.createSpy('fooHandler')
fragment.on 'foo', fooHandler
target = fragment.find('.child-node')[0]
keymap.handleKeyEvent(keydownEvent('z', target: target))
expect(fooHandler).toHaveBeenCalled()
describe ".keystrokeStringForEvent(event)", ->
describe "when no modifiers are pressed", ->
it "returns a string that identifies the key pressed", ->
@@ -224,3 +212,24 @@ describe "Keymap", ->
expect(keymap.keystrokeStringForEvent(keydownEvent('{', shiftKey: true))).toBe '{'
expect(keymap.keystrokeStringForEvent(keydownEvent('left', shiftKey: true))).toBe 'shift-left'
expect(keymap.keystrokeStringForEvent(keydownEvent('Left', shiftKey: true))).toBe 'shift-left'
describe ".bindingsForElement(element)", ->
it "returns the matching bindings for the element", ->
keymap.bindKeys '.command-mode', 'c': 'c'
keymap.bindKeys '.grandchild-node', 'g': 'g'
bindings = keymap.bindingsForElement(fragment.find('.grandchild-node'))
expect(Object.keys(bindings).length).toBe 2
expect(bindings['c']).toEqual "c"
expect(bindings['g']).toEqual "g"
describe "when multiple bindings match a keystroke", ->
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"

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'