Replace previous character when inserting accented characters

This commit is contained in:
Nathan Sobo
2014-04-10 12:41:36 -06:00
parent 96ebb9bf03
commit 022f5ca219
2 changed files with 17 additions and 3 deletions

View File

@@ -2,7 +2,7 @@ React = require 'react'
{extend, flatten, toArray} = require 'underscore-plus'
EditorComponent = require '../src/editor-component'
describe "EditorComponent", ->
fdescribe "EditorComponent", ->
[editor, component, node, lineHeightInPixels, charWidth, delayAnimationFrames, nextAnimationFrame] = []
beforeEach ->
@@ -489,3 +489,13 @@ describe "EditorComponent", ->
node.dispatchEvent(new WheelEvent('mousewheel', wheelDeltaX: -15, wheelDeltaY: -5))
expect(verticalScrollbarNode.scrollTop).toBe 10
expect(horizontalScrollbarNode.scrollLeft).toBe 15
describe "input events", ->
it "inserts the typed character into the buffer", ->
component.onInput('x')
expect(editor.lineForBufferRow(0)).toBe 'xvar quicksort = function () {'
it "replaces the last character if replaceLastCharacter is true", ->
component.onInput('u')
component.onInput('ü', true)
expect(editor.lineForBufferRow(0)).toBe 'üvar quicksort = function () {'

View File

@@ -332,8 +332,12 @@ EditorCompont = React.createClass
onInputBlurred: ->
@setState(focused: false) unless document.activeElement is @getDOMNode()
onInput: (char, replaceLastChar) ->
ReactUpdates.batchedUpdates => @props.editor.insertText(char)
onInput: (char, replaceLastCharacter) ->
{editor} = @props
ReactUpdates.batchedUpdates ->
editor.selectLeft() if replaceLastCharacter
editor.insertText(char)
onVerticalScroll: ->
scrollTop = @refs.verticalScrollbar.getDOMNode().scrollTop