diff --git a/spec/editor-component-spec.coffee b/spec/editor-component-spec.coffee index 3d8a303d7..631434ac5 100644 --- a/spec/editor-component-spec.coffee +++ b/spec/editor-component-spec.coffee @@ -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') diff --git a/src/cursor-component.coffee b/src/cursor-component.coffee index 5fa7f10b2..a347d9565 100644 --- a/src/cursor-component.coffee +++ b/src/cursor-component.coffee @@ -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} diff --git a/src/cursors-component.coffee b/src/cursors-component.coffee index 62c471c49..eb1cc14b6 100644 --- a/src/cursors-component.coffee +++ b/src/cursors-component.coffee @@ -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