GlobalKeymap.handleKeyEvent does not stop event propagation if no binding matches.

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-01-11 12:51:42 -08:00
parent 278ac6a9f2
commit 83a68dbbb0
3 changed files with 12 additions and 12 deletions

View File

@@ -142,17 +142,17 @@ describe "Editor", ->
editor.aceEditor.onCommandKey event, 0, event.which
expect(handler.handleKeyEvent).toHaveBeenCalled()
describe "if the atom key event handler returns false, indicating that it did not handle the event", ->
describe "if the atom key event handler returns true, indicating that it did not handle the event", ->
beforeEach ->
returnValue = false
returnValue = true
it "does not stop the propagation of the event, allowing Ace to handle it as normal", ->
editor.aceEditor.onCommandKey event, 0, event.which
expect(event.stopPropagation).not.toHaveBeenCalled()
describe "if the atom key event handler returns true, indicating that it handled the event", ->
describe "if the atom key event handler returns false, indicating that it handled the event", ->
beforeEach ->
returnValue = true
returnValue = false
it "stops propagation of the event, so Ace does not attempt to handle it", ->
editor.aceEditor.onCommandKey event, 0, event.which

View File

@@ -30,9 +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 and returns true", ->
it "triggers the command event associated with that binding on the target node and returns false", ->
result = keymap.handleKeyEvent(keypressEvent('x', target: fragment[0]))
expect(result).toBeTruthy()
expect(result).toBe(false)
expect(deleteCharHandler).toHaveBeenCalled()
expect(insertCharHandler).not.toHaveBeenCalled()
@@ -44,14 +44,14 @@ describe "GlobalKeymap", ->
expect(insertCharHandler).toHaveBeenCalled()
describe "when no binding matches the event", ->
it "returns false", ->
expect(keymap.handleKeyEvent(keypressEvent('0', target: fragment[0]))).toBe(false)
it "returns true, so the event continues to propagate", ->
expect(keymap.handleKeyEvent(keypressEvent('0', target: fragment[0]))).toBeTruthy()
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 and returns true", ->
it "triggers the command event associated with that binding on the target node and returns false", ->
target = fragment.find('.child-node')[0]
result = keymap.handleKeyEvent(keypressEvent('x', target: target))
expect(result).toBeTruthy()
expect(result).toBe(false)
expect(deleteCharHandler).toHaveBeenCalled()
expect(insertCharHandler).not.toHaveBeenCalled()

View File

@@ -20,9 +20,9 @@ class GlobalKeymap
for bindingSet in candidateBindingSets
if command = bindingSet.commandForEvent(event)
$(event.target).trigger(command)
return true
return false
currentNode = currentNode.parent()
false
true
reset: ->
@BindingSets = []