Make react cursor the width of a default character at the end of lines

When the cursor is positioned before a character, we always make it the
width of that character. But at the end of a line, there is no character
to use to set the width, so we just use the defaultCharWidth.

This makes the block cursor visible on empty lines in vim-mode.
This commit is contained in:
Nathan Sobo 2014-06-11 11:53:51 -06:00
parent f1628fb1e0
commit 030bcd6d4f
3 changed files with 9 additions and 3 deletions

View File

@ -630,6 +630,11 @@ describe "EditorComponent", ->
expect(cursorRect.left).toBe rangeRect.left
expect(cursorRect.width).toBe rangeRect.width
it "sets the cursor to the default character width at the end of a line", ->
editor.setCursorScreenPosition([0, Infinity])
cursorNode = node.querySelector('.cursor')
expect(cursorNode.offsetWidth).toBe charWidth
it "gives the cursor a non-zero width even if it's inside atomic tokens", ->
editor.setCursorScreenPosition([1, 0])
cursorNode = node.querySelector('.cursor')

View File

@ -6,10 +6,11 @@ CursorComponent = React.createClass
displayName: 'CursorComponent'
render: ->
{editor, screenRange, scrollTop, scrollLeft} = @props
{editor, screenRange, scrollTop, scrollLeft, defaultCharWidth} = @props
{top, left, height, width} = editor.pixelRectForScreenRange(screenRange)
top -= scrollTop
left -= scrollLeft
width = defaultCharWidth if width is 0
WebkitTransform = "translate3d(#{left}px, #{top}px, 0px)"
div className: 'cursor', style: {height, width, WebkitTransform}

View File

@ -12,7 +12,7 @@ CursorsComponent = React.createClass
cursorBlinkIntervalHandle: null
render: ->
{editor, cursorScreenRanges, scrollTop, scrollLeft} = @props
{editor, cursorScreenRanges, scrollTop, scrollLeft, defaultCharWidth} = @props
{blinkOff} = @state
className = 'cursors'
@ -21,7 +21,7 @@ CursorsComponent = React.createClass
div {className},
if @isMounted()
for key, screenRange of cursorScreenRanges
CursorComponent({key, editor, screenRange, scrollTop, scrollLeft})
CursorComponent({key, editor, screenRange, scrollTop, scrollLeft, defaultCharWidth})
getInitialState: ->
blinkOff: false