Merge remote-tracking branch 'origin/master' into cj-expose-resizing-to-editor

This commit is contained in:
probablycorey
2014-06-17 17:22:10 -07:00
19 changed files with 182 additions and 69 deletions

View File

@@ -114,9 +114,10 @@ class Cursor extends Model
# Public: Get the RegExp used by the cursor to determine what a "word" is.
#
# options: An {Object} with the following keys:
# options: An optional {Object} with the following keys:
# :includeNonWordCharacters - A {Boolean} indicating whether to include
# non-word characters in the regex.
# (default: true)
#
# Returns a {RegExp}.
wordRegExp: ({includeNonWordCharacters}={})->

View File

@@ -84,7 +84,6 @@ EditorComponent = React.createClass
ref: 'input'
className: 'hidden-input'
style: hiddenInputStyle
onInput: @onInput
onFocus: @onInputFocused
onBlur: @onInputBlurred
@@ -268,6 +267,7 @@ EditorComponent = React.createClass
node = @getDOMNode()
node.addEventListener 'mousewheel', @onMouseWheel
node.addEventListener 'focus', @onFocus # For some reason, React's built in focus events seem to bubble
node.addEventListener 'textInput', @onTextInput
scrollViewNode = @refs.scrollView.getDOMNode()
scrollViewNode.addEventListener 'scroll', @onScrollViewScroll
@@ -393,6 +393,26 @@ EditorComponent = React.createClass
onFocus: ->
@refs.input.focus()
onTextInput: (event) ->
return unless @isInputEnabled()
{editor} = @props
inputNode = event.target
# Work around of the accented character suggestion feature in OS X.
# Text input fires before a character is inserted, and if the browser is
# replacing the previous un-accented character with an accented variant, it
# will select backward over it.
selectedLength = inputNode.selectionEnd - inputNode.selectionStart
editor.selectLeft() if selectedLength is 1
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)
@@ -453,19 +473,9 @@ EditorComponent = React.createClass
scrollViewNode.scrollTop = 0
scrollViewNode.scrollLeft = 0
onInput: (char, replaceLastCharacter) ->
return unless @inputEnabled
{editor} = @props
if replaceLastCharacter
editor.transact ->
editor.selectLeft()
editor.insertText(char)
else
editor.insertText(char)
onMouseDown: (event) ->
return unless event.button is 0 # only handle the left mouse button
{editor} = @props
{detail, shiftKey, metaKey} = event
screenPosition = @screenPositionForMouseEvent(event)

View File

@@ -368,6 +368,8 @@ class EditorView extends View
false if @isFocused
@overlayer.on 'mousedown', (e) =>
return unless e.which is 1 # only handle the left mouse button
@overlayer.hide()
clickedElement = document.elementFromPoint(e.pageX, e.pageY)
@overlayer.show()
@@ -567,7 +569,7 @@ class EditorView extends View
@scrollTop(scrollTop)
@subscribe @editor, 'scroll-left-changed', (scrollLeft) =>
@scrollLeft(scrollLeft)
@scrollView.scrollLeft(scrollLeft)
@subscribe @editor, 'soft-wrap-changed', (softWrap) =>
@setSoftWrap(softWrap)

View File

@@ -1,4 +1,3 @@
punycode = require 'punycode'
{last, isEqual} = require 'underscore-plus'
React = require 'react-atom-fork'
{input} = require 'reactionary-atom-fork'
@@ -17,7 +16,6 @@ InputComponent = React.createClass
componentDidMount: ->
@getDOMNode().addEventListener 'paste', @onPaste
@getDOMNode().addEventListener 'input', @onInput
@getDOMNode().addEventListener 'compositionupdate', @onCompositionUpdate
# Don't let text accumulate in the input forever, but avoid excessive reflows
@@ -36,15 +34,6 @@ InputComponent = React.createClass
onPaste: (e) ->
e.preventDefault()
onInput: (e) ->
e.stopPropagation()
valueCharCodes = punycode.ucs2.decode(@getDOMNode().value)
valueLength = valueCharCodes.length
replaceLastChar = valueLength is @lastValueLength
@lastValueLength = valueLength
lastChar = String.fromCharCode(last(valueCharCodes))
@props.onInput?(lastChar, replaceLastChar)
onFocus: ->
@props.onFocus?()