Merge pull request #15051 from atom/ns-mb-measurements-with-pending-updates

Fix exceptions when measuring pixel positions with pending content updates
This commit is contained in:
Bryant Ung
2017-07-18 16:08:58 -07:00
committed by GitHub
2 changed files with 12 additions and 3 deletions

View File

@@ -3335,6 +3335,15 @@ describe('TextEditorComponent', () => {
expect(left).toBe(clientLeftForCharacter(referenceComponent, 12, 1) - referenceContentRect.left)
}
})
it('does not get the component into an inconsistent state when the model has unflushed changes (regression)', async () => {
const {component, element, editor} = buildComponent({rowsPerTile: 2, autoHeight: false, text: ''})
await setEditorHeightInLines(component, 10)
const updatePromise = editor.getBuffer().append("hi\n")
component.screenPositionForPixelPosition({top: 800, left: 1})
await updatePromise
})
})
describe('screenPositionForPixelPosition', () => {

View File

@@ -251,20 +251,17 @@ class TextEditorComponent {
this.measureBlockDecorations()
this.measuredContent = false
this.updateSyncBeforeMeasuringContent()
if (useScheduler === true) {
const scheduler = etch.getScheduler()
scheduler.readDocument(() => {
this.measureContentDuringUpdateSync()
this.measuredContent = true
scheduler.updateDocument(() => {
this.updateSyncAfterMeasuringContent()
})
})
} else {
this.measureContentDuringUpdateSync()
this.measuredContent = true
this.updateSyncAfterMeasuringContent()
}
}
@@ -341,6 +338,7 @@ class TextEditorComponent {
}
updateSyncBeforeMeasuringContent () {
this.measuredContent = false
this.derivedDimensionsCache = {}
this.updateModelSoftWrapColumn()
if (this.pendingAutoscroll) {
@@ -384,6 +382,8 @@ class TextEditorComponent {
}
this.pendingAutoscroll = null
}
this.measuredContent = true
}
updateSyncAfterMeasuringContent () {