Update DOM in screenPositionForPixelPosition if needed

Some packages are interacting with this method assuming this behavior,
so this commit eliminates `screenPositionForPixelPositionSync` and
instead just performs the DOM update in `screenPositionForPixelPosition`
if it is needed.
This commit is contained in:
Nathan Sobo
2017-05-04 14:09:45 -06:00
committed by Antonio Scandurra
parent 001fef4a05
commit fe13279531
3 changed files with 14 additions and 23 deletions

View File

@@ -3112,7 +3112,7 @@ describe('TextEditorComponent', () => {
})
})
describe('screenPositionForPixelPositionSync', () => {
describe('screenPositionForPixelPosition', () => {
it('returns the screen position for the given pixel position, regardless of whether or not it is currently on screen', async () => {
const {component, element, editor} = buildComponent({rowsPerTile: 2, autoHeight: false})
await setEditorHeightInLines(component, 3)
@@ -3123,28 +3123,28 @@ describe('TextEditorComponent', () => {
const pixelPosition = referenceComponent.pixelPositionForScreenPositionSync({row: 0, column: 0})
pixelPosition.top += component.getLineHeight() / 3
pixelPosition.left += component.getBaseCharacterWidth() / 3
expect(component.screenPositionForPixelPositionSync(pixelPosition)).toEqual([0, 0])
expect(component.screenPositionForPixelPosition(pixelPosition)).toEqual([0, 0])
}
{
const pixelPosition = referenceComponent.pixelPositionForScreenPositionSync({row: 0, column: 5})
pixelPosition.top += component.getLineHeight() / 3
pixelPosition.left += component.getBaseCharacterWidth() / 3
expect(component.screenPositionForPixelPositionSync(pixelPosition)).toEqual([0, 5])
expect(component.screenPositionForPixelPosition(pixelPosition)).toEqual([0, 5])
}
{
const pixelPosition = referenceComponent.pixelPositionForScreenPositionSync({row: 5, column: 7})
pixelPosition.top += component.getLineHeight() / 3
pixelPosition.left += component.getBaseCharacterWidth() / 3
expect(component.screenPositionForPixelPositionSync(pixelPosition)).toEqual([5, 7])
expect(component.screenPositionForPixelPosition(pixelPosition)).toEqual([5, 7])
}
{
const pixelPosition = referenceComponent.pixelPositionForScreenPositionSync({row: 12, column: 1})
pixelPosition.top += component.getLineHeight() / 3
pixelPosition.left += component.getBaseCharacterWidth() / 3
expect(component.screenPositionForPixelPositionSync(pixelPosition)).toEqual([12, 1])
expect(component.screenPositionForPixelPosition(pixelPosition)).toEqual([12, 1])
}
})
})

View File

@@ -173,22 +173,6 @@ class TextEditorComponent {
return {top, left}
}
screenPositionForPixelPositionSync (pixelPosition) {
const {model} = this.props
const row = Math.max(0, Math.min(
this.rowForPixelPosition(pixelPosition.top),
model.getApproximateScreenLineCount() - 1
))
if (!this.renderedScreenLineForRow(row)) {
this.requestExtraLineToMeasure(row, model.screenLineForScreenRow(row))
this.updateSyncBeforeMeasuringContent()
this.measureContentDuringUpdateSync()
}
return this.screenPositionForPixelPosition(pixelPosition)
}
scheduleUpdate (nextUpdateOnlyBlinksCursors = false) {
if (!this.visible) return
@@ -2181,9 +2165,16 @@ class TextEditorComponent {
model.getApproximateScreenLineCount() - 1
)
let screenLine = this.renderedScreenLineForRow(row)
if (!screenLine) {
this.requestExtraLineToMeasure(row, model.screenLineForScreenRow(row))
this.updateSyncBeforeMeasuringContent()
this.measureContentDuringUpdateSync()
screenLine = this.renderedScreenLineForRow(row)
}
const linesClientLeft = this.refs.lineTiles.getBoundingClientRect().left
const targetClientLeft = linesClientLeft + Math.max(0, left)
const screenLine = this.renderedScreenLineForRow(row)
const textNodes = this.textNodesByScreenLineId.get(screenLine.id)
let containingTextNodeIndex

View File

@@ -245,7 +245,7 @@ class TextEditorElement extends HTMLElement {
}
screenPositionForPixelPosition (pixelPosition) {
return this.getComponent().screenPositionForPixelPositionSync(pixelPosition)
return this.getComponent().screenPositionForPixelPosition(pixelPosition)
}
pixelRectForScreenRange (range) {