From eebd312af9025a9b743789a82b8973dfd11c4e05 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Fri, 2 Nov 2012 13:23:45 -0600 Subject: [PATCH] Add Keymap benchmark for handling an event with no binding --- benchmark/benchmark-helper.coffee | 29 +++++++---------------------- benchmark/benchmark-suite.coffee | 9 +++++++++ 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/benchmark/benchmark-helper.coffee b/benchmark/benchmark-helper.coffee index 2fe689ecc..8167383e1 100644 --- a/benchmark/benchmark-helper.coffee +++ b/benchmark/benchmark-helper.coffee @@ -70,30 +70,15 @@ window.waitsForPromise = (fn) -> window.waitsFor (moveOn) -> fn().done(moveOn) -window.eventPropertiesForPattern = (pattern) -> - [modifiers..., key] = pattern.split '-' - - 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 +window.keyIdentifierForKey = (key) -> + if key.length > 1 # named key + key else - keyIdentifier = "U+00" + charCode.toString(16) + charCode = key.toUpperCase().charCodeAt(0) + "U+00" + charCode.toString(16) - ctrlKey: 'ctrl' in modifiers - altKey: 'alt' in modifiers - 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.keydownEvent = (key, properties={}) -> + $.Event "keydown", _.extend({originalEvent: { keyIdentifier: keyIdentifierForKey(key) }}, properties) window.clickEvent = (properties={}) -> $.Event "click", properties diff --git a/benchmark/benchmark-suite.coffee b/benchmark/benchmark-suite.coffee index 10d5badb7..4b5e79f1d 100644 --- a/benchmark/benchmark-suite.coffee +++ b/benchmark/benchmark-suite.coffee @@ -23,6 +23,15 @@ describe "editor.", -> window.shutdown() 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.", -> benchmark "300-line-file.", -> buffer = rootView.project.bufferForPath('medium.coffee')