Give cursors at the end of lines the width of an 'x' character

This commit is contained in:
Nathan Sobo
2017-04-15 12:30:20 -06:00
committed by Antonio Scandurra
parent 87eb16f5ed
commit f83ad6bb7c
2 changed files with 13 additions and 4 deletions

View File

@@ -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

View File

@@ -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