Only clear linesToMeasure when we have actually measured

Previously, as soon as we decided to render linesToMeasure, we would
clear them out. However, if a second update interleaved with the update
that initially requested measurement, it could cause the requested lines
to not be present when the measurement phase from the first update
occurred. Now, any additional updates will only add to the set of lines
that need to be measured until the measurement phase actually happens.

Signed-off-by: Antonio Scandurra <as-cii@github.com>
This commit is contained in:
Nathan Sobo
2017-08-16 11:28:58 -06:00
committed by Antonio Scandurra
parent da2c3fb56b
commit c626836b2e
2 changed files with 21 additions and 1 deletions

View File

@@ -117,6 +117,22 @@ describe('TextEditorComponent', () => {
)
expect(actualWidth).toBe(expectedWidth + 'px')
}
{
// Make sure we do not throw an error if a synchronous update is
// triggered before measuring the longest line from a
// previously-scheduled update.
editor.getBuffer().insert(Point(12, Infinity), 'x'.repeat(100))
expect(editor.getLongestScreenRow()).toBe(12)
TextEditorComponent.getScheduler().readDocument(() => {
// This will happen before the measurement phase of the update
// triggered above.
component.pixelPositionForScreenPosition(Point(11, Infinity))
})
await component.getNextUpdatePromise()
}
})
it('re-renders lines when their height changes', async () => {

View File

@@ -32,6 +32,10 @@ class TextEditorComponent {
etch.setScheduler(scheduler)
}
static getScheduler () {
return etch.getScheduler()
}
static didUpdateStyles () {
if (this.attachedComponents) {
this.attachedComponents.forEach((component) => {
@@ -389,6 +393,7 @@ class TextEditorComponent {
this.pendingAutoscroll = null
}
this.linesToMeasure.clear()
this.measuredContent = true
}
@@ -848,7 +853,6 @@ class TextEditorComponent {
this.extraRenderedScreenLines.set(row, screenLine)
}
})
this.linesToMeasure.clear()
}
queryLineNumbersToRender () {