mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Bind keydown on root view to catch events that aren't handled by ace
Also fixed a bug where the GlobalKeymap wasn't returning true when it matched a binding, which caused key events to be processed twice when they bubbled out of the editor and hit the root view.
This commit is contained in:
committed by
Corey Johnson & Nathan Sobo
parent
7f4120ce36
commit
2a80a72d64
@@ -161,12 +161,6 @@ describe "Editor", ->
|
||||
describe "when onTextInput is called on the aceEditor (triggered by an input event)", ->
|
||||
it "does not call handleKeyEvent on the key event handler, because there is no event", ->
|
||||
editor.keyEventHandler = handler
|
||||
|
||||
editor.aceEditor.onTextInput("x", false)
|
||||
|
||||
expect(handler.handleKeyEvent).not.toHaveBeenCalled()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -30,8 +30,9 @@ describe "GlobalKeymap", ->
|
||||
fragment.on 'insertChar', insertCharHandler
|
||||
|
||||
describe "when the event's target node matches a selector with a matching binding", ->
|
||||
it "triggers the command event associated with that binding on the target node", ->
|
||||
keymap.handleKeyEvent(keypressEvent('x', target: fragment[0]))
|
||||
it "triggers the command event associated with that binding on the target node and returns true", ->
|
||||
result = keymap.handleKeyEvent(keypressEvent('x', target: fragment[0]))
|
||||
expect(result).toBeTruthy()
|
||||
expect(deleteCharHandler).toHaveBeenCalled()
|
||||
expect(insertCharHandler).not.toHaveBeenCalled()
|
||||
|
||||
@@ -47,9 +48,10 @@ describe "GlobalKeymap", ->
|
||||
expect(keymap.handleKeyEvent(keypressEvent('0', target: fragment[0]))).toBe(false)
|
||||
|
||||
describe "when the event's target node *descends* from a selector with a matching binding", ->
|
||||
it "triggers the command event associated with that binding on the target node", ->
|
||||
it "triggers the command event associated with that binding on the target node and returns true", ->
|
||||
target = fragment.find('.child-node')[0]
|
||||
keymap.handleKeyEvent(keypressEvent('x', target: target))
|
||||
result = keymap.handleKeyEvent(keypressEvent('x', target: target))
|
||||
expect(result).toBeTruthy()
|
||||
expect(deleteCharHandler).toHaveBeenCalled()
|
||||
expect(insertCharHandler).not.toHaveBeenCalled()
|
||||
|
||||
|
||||
@@ -81,15 +81,24 @@ describe "RootView", ->
|
||||
rootView.fileFinder.select()
|
||||
expect(rootView.editor.buffer.url).toBe(project.url + firstLi.text())
|
||||
|
||||
describe "when a key is typed in the editor that has a binding in the keymap", ->
|
||||
it "triggers the key binding's command as an event and does not insert a character", ->
|
||||
rootView.globalKeymap.bindKeys('.editor', 'x': 'fooCommand')
|
||||
describe "global keymap wiring", ->
|
||||
commandHandler = null
|
||||
beforeEach ->
|
||||
commandHandler = jasmine.createSpy('commandHandler')
|
||||
rootView.on('foo-command', commandHandler)
|
||||
rootView.globalKeymap.bindKeys('*', 'x': 'foo-command')
|
||||
|
||||
fooCommandHandler = jasmine.createSpy('fooCommandHandler')
|
||||
rootView.editor.on('fooCommand', fooCommandHandler)
|
||||
describe "when a key is typed in the editor that has a binding in the keymap", ->
|
||||
it "triggers the key binding's command as an event and stops its propagation", ->
|
||||
event = keydownEvent 'x', target: rootView.find('textarea')[0]
|
||||
spyOn event, 'stopPropagation'
|
||||
rootView.editor.aceEditor.onCommandKey event, 0, event.which
|
||||
expect(commandHandler).toHaveBeenCalled()
|
||||
expect(event.stopPropagation).toHaveBeenCalled()
|
||||
|
||||
event = keydownEvent 'x', target: rootView.find('textarea')[0]
|
||||
rootView.editor.aceEditor.onCommandKey event, 0, event.which
|
||||
|
||||
expect(fooCommandHandler).toHaveBeenCalled()
|
||||
describe "when a keydown event is triggered on the RootView (not originating from Ace)", ->
|
||||
it "triggers matching keybindings for that event", ->
|
||||
event = keydownEvent 'x', target: rootView[0]
|
||||
rootView.trigger(event)
|
||||
expect(commandHandler).toHaveBeenCalled()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user