From f83ad6bb7c1db3f1c166050dccf908ccc486f7c8 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Sat, 15 Apr 2017 12:30:20 -0600 Subject: [PATCH] Give cursors at the end of lines the width of an 'x' character --- spec/text-editor-component-spec.js | 7 +++++++ src/text-editor-component.js | 10 ++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/spec/text-editor-component-spec.js b/spec/text-editor-component-spec.js index f4324505b..400af0a42 100644 --- a/spec/text-editor-component-spec.js +++ b/spec/text-editor-component-spec.js @@ -320,6 +320,13 @@ describe('TextEditorComponent', () => { expect(getComputedStyle(cursor2).opacity).toBe('1') }) + it('gives cursors at the end of lines the width of an "x" character', async () => { + const {component, element, editor} = buildComponent() + editor.setCursorScreenPosition([0, Infinity]) + await component.getNextUpdatePromise() + expect(element.querySelector('.cursor').offsetWidth).toBe(Math.round(component.getBaseCharacterWidth())) + }) + it('places the hidden input element at the location of the last cursor if it is visible', async () => { const {component, element, editor} = buildComponent({height: 60, width: 120, rowsPerTile: 2}) const {hiddenInput} = component.refs diff --git a/src/text-editor-component.js b/src/text-editor-component.js index da50885c4..ded80019a 100644 --- a/src/text-editor-component.js +++ b/src/text-editor-component.js @@ -1086,10 +1086,12 @@ class TextEditorComponent { const pixelTop = this.pixelPositionAfterBlocksForRow(row) const pixelLeft = this.pixelLeftForRowAndColumn(row, column) - const pixelRight = (cursor.columnWidth === 0) - ? pixelLeft - : this.pixelLeftForRowAndColumn(row, column + 1) - const pixelWidth = pixelRight - pixelLeft + let pixelWidth + if (cursor.columnWidth === 0) { + pixelWidth = this.getBaseCharacterWidth() + } else { + pixelWidth = this.pixelLeftForRowAndColumn(row, column + 1) - pixelLeft + } const cursorPosition = {pixelTop, pixelLeft, pixelWidth} this.decorationsToRender.cursors[i] = cursorPosition