mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-10 10:17:11 +03:00
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:
parent
f1628fb1e0
commit
030bcd6d4f
@ -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')
|
||||
|
@ -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}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user