Stop propagation of keydown/textInput events to prevent React handler

React's global synthetic event handler is somewhat expensive. This
prevents it from being invoked on every keystroke, saving ~1ms.
This commit is contained in:
Nathan Sobo
2014-07-30 11:26:15 -06:00
parent f25b468272
commit 6e72627e9e
2 changed files with 11 additions and 5 deletions

View File

@@ -524,6 +524,12 @@ EditorComponent = React.createClass
@refs.input.focus()
onTextInput: (event) ->
event.stopPropagation()
# If we prevent the insertion of a space character, then the browser
# interprets the spacebar keypress as a page-down command.
event.preventDefault() unless event.data is ' '
return unless @isInputEnabled()
{editor} = @props
@@ -539,9 +545,6 @@ EditorComponent = React.createClass
editor.insertText(event.data)
inputNode.value = event.data
# If we prevent the insertion of a space character, then the browser
# interprets the spacebar keypress as a page-down command.
event.preventDefault() unless event.data is ' '
onInputFocused: ->
@setState(focused: true)

View File

@@ -57,8 +57,7 @@ class WindowEventHandler
@subscribeToCommand $(document), 'core:focus-previous', @focusPrevious
@subscribe $(document), 'keydown', (event) ->
atom.keymaps.handleKeyboardEvent(event.originalEvent)
document.addEventListener 'keydown', @onKeydown
@subscribe $(document), 'drop', (e) ->
e.preventDefault()
@@ -95,6 +94,10 @@ class WindowEventHandler
bindCommandToAction('core:redo', 'redo:')
bindCommandToAction('core:select-all', 'selectAll:')
onKeydown: (event) ->
atom.keymaps.handleKeyboardEvent(event)
event.stopImmediatePropagation()
openLink: ({target, currentTarget}) ->
location = target?.getAttribute('href') or currentTarget?.getAttribute('href')
if location and location[0] isnt '#' and /^https?:\/\//.test(location)