mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
This commit also changes input handling to be more like it was in the previous editor. We're using textInput rather than input events because they are emitted *before* characters are inserted, enabling much simpler detection of characters inserted via the accented-character menu on OS X. Previously I avoided this because something about it was causing reflows in the old editor, but in this editor that doesn't seem to be a problem, and it's actually faster.
45 lines
1.2 KiB
CoffeeScript
45 lines
1.2 KiB
CoffeeScript
{last, isEqual} = require 'underscore-plus'
|
|
React = require 'react-atom-fork'
|
|
{input} = require 'reactionary-atom-fork'
|
|
|
|
module.exports =
|
|
InputComponent = React.createClass
|
|
displayName: 'InputComponent'
|
|
|
|
render: ->
|
|
{className, style, onFocus, onBlur} = @props
|
|
|
|
input {className, style, onFocus, onBlur, 'data-react-skip-selection-restoration': true}
|
|
|
|
getInitialState: ->
|
|
{lastChar: ''}
|
|
|
|
componentDidMount: ->
|
|
@getDOMNode().addEventListener 'paste', @onPaste
|
|
@getDOMNode().addEventListener 'compositionupdate', @onCompositionUpdate
|
|
|
|
# Don't let text accumulate in the input forever, but avoid excessive reflows
|
|
componentDidUpdate: ->
|
|
if @lastValueLength > 500 and not @isPressAndHoldCharacter(@state.lastChar)
|
|
@getDOMNode().value = ''
|
|
@lastValueLength = 0
|
|
|
|
# This should actually consult the property lists in /System/Library/Input Methods/PressAndHold.app
|
|
isPressAndHoldCharacter: (char) ->
|
|
@state.lastChar.match /[aeiouAEIOU]/
|
|
|
|
shouldComponentUpdate: (newProps) ->
|
|
not isEqual(newProps.style, @props.style)
|
|
|
|
onPaste: (e) ->
|
|
e.preventDefault()
|
|
|
|
onFocus: ->
|
|
@props.onFocus?()
|
|
|
|
onBlur: ->
|
|
@props.onBlur?()
|
|
|
|
focus: ->
|
|
@getDOMNode().focus()
|