From 6e919e7acd9feae92f3548fb2d35279cbb2e8e51 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Sat, 2 Sep 2017 11:11:27 +0200 Subject: [PATCH] Don't remeasure invalid block decorations This fixes an uncaught exception that was being thrown after invalidating a marker and resizing the editor. --- spec/text-editor-component-spec.js | 17 +++++++++++++++++ src/text-editor-component.js | 3 ++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/spec/text-editor-component-spec.js b/spec/text-editor-component-spec.js index 222b02492..311759bac 100644 --- a/spec/text-editor-component-spec.js +++ b/spec/text-editor-component-spec.js @@ -2371,6 +2371,23 @@ describe('TextEditorComponent', () => { ]) }) + it('does not try to remeasure block decorations whose markers are invalid (regression)', async () => { + const editor = buildEditor({rowsPerTile: 3, autoHeight: false}) + const {component, element} = buildComponent({editor, rowsPerTile: 3}) + const {decoration, marker} = createBlockDecorationAtScreenRow(editor, 2, {height: '12px', invalidate: 'touch'}) + editor.getBuffer().deleteRows(0, 3) + await component.getNextUpdatePromise() + + // Trigger a re-measurement of all block decorations. + await setEditorWidthInCharacters(component, 20) + assertLinesAreAlignedWithLineNumbers(component) + assertTilesAreSizedAndPositionedCorrectly(component, [ + {tileStartRow: 0, height: 3 * component.getLineHeight()}, + {tileStartRow: 3, height: 3 * component.getLineHeight()}, + {tileStartRow: 6, height: 3 * component.getLineHeight()} + ]) + }) + it('measures block decorations correctly when they are added before the component width has been updated', async () => { { const {editor, component, element} = buildComponent({autoHeight: false, width: 500, attach: false}) diff --git a/src/text-editor-component.js b/src/text-editor-component.js index 78c003276..61868228b 100644 --- a/src/text-editor-component.js +++ b/src/text-editor-component.js @@ -286,7 +286,8 @@ class TextEditorComponent { const decorations = this.props.model.getDecorations() for (var i = 0; i < decorations.length; i++) { const decoration = decorations[i] - if (decoration.getProperties().type === 'block') { + const marker = decoration.getMarker() + if (marker.isValid() && decoration.getProperties().type === 'block') { this.blockDecorationsToMeasure.add(decoration) } }