Add Keymap benchmark for handling an event with no binding

This commit is contained in:
Nathan Sobo 2012-11-02 13:23:45 -06:00
parent 045cdda41d
commit eebd312af9
2 changed files with 16 additions and 22 deletions

View File

@ -70,30 +70,15 @@ window.waitsForPromise = (fn) ->
window.waitsFor (moveOn) -> window.waitsFor (moveOn) ->
fn().done(moveOn) fn().done(moveOn)
window.eventPropertiesForPattern = (pattern) -> window.keyIdentifierForKey = (key) ->
[modifiers..., key] = pattern.split '-' if key.length > 1 # named key
key
modifiers.push 'shift' if key == key.toUpperCase() and key.toUpperCase() != key.toLowerCase()
charCode = key.toUpperCase().charCodeAt 0
isNamedKey = key.length > 1
if isNamedKey
keyIdentifier = key
else else
keyIdentifier = "U+00" + charCode.toString(16) charCode = key.toUpperCase().charCodeAt(0)
"U+00" + charCode.toString(16)
ctrlKey: 'ctrl' in modifiers window.keydownEvent = (key, properties={}) ->
altKey: 'alt' in modifiers $.Event "keydown", _.extend({originalEvent: { keyIdentifier: keyIdentifierForKey(key) }}, properties)
shiftKey: 'shift' in modifiers
metaKey: 'meta' in modifiers
which: charCode
originalEvent:
keyIdentifier: keyIdentifier
window.keydownEvent = (pattern, properties={}) ->
event = $.Event "keydown", _.extend(eventPropertiesForPattern(pattern), properties)
# event.keystroke = (new Keymap).keystrokeStringForEvent(event)
event
window.clickEvent = (properties={}) -> window.clickEvent = (properties={}) ->
$.Event "click", properties $.Event "click", properties

View File

@ -23,6 +23,15 @@ describe "editor.", ->
window.shutdown() window.shutdown()
atom.setRootViewStateForPath(rootView.project.getPath(), null) atom.setRootViewStateForPath(rootView.project.getPath(), null)
describe "keymap.", ->
event = null
beforeEach ->
event = keydownEvent('x', target: editor.hiddenInput[0])
benchmark "keydown-event-with-no-binding", 10, ->
keymap.handleKeyEvent(event)
describe "opening-buffers.", -> describe "opening-buffers.", ->
benchmark "300-line-file.", -> benchmark "300-line-file.", ->
buffer = rootView.project.bufferForPath('medium.coffee') buffer = rootView.project.bufferForPath('medium.coffee')