Skip to content

Commit c1981ff

Browse files
author
Antonio Scandurra
committed
Correctly remove block decorations whose markers have been destroyed
In atom#15503 we mistakenly assumed `marker.isValid` accounted only for the validity of the marker. However, that method returns `false` also for markers that are valid but have been destroyed. As a result, the editor component was mistakenly not removing block decorations associated with such markers. With this commit we will rely on the local `wasValid` variable instead. If its value is `true`, it means that the block decoration has been accounted for in the `lineTopIndex` and must, as a result, be cleaned up in case the marker or the decoration gets destroyed.
1 parent 4b3fa34 commit c1981ff

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

spec/text-editor-component-spec.js

+21
Original file line numberDiff line numberDiff line change
@@ -2299,6 +2299,27 @@ describe('TextEditorComponent', () => {
22992299
])
23002300
})
23012301

2302+
it('removes block decorations whose markers have been destroyed', async () => {
2303+
const {editor, component, element} = buildComponent({rowsPerTile: 3})
2304+
const {marker} = createBlockDecorationAtScreenRow(editor, 2, {height: 5, position: 'before'})
2305+
await component.getNextUpdatePromise()
2306+
assertLinesAreAlignedWithLineNumbers(component)
2307+
assertTilesAreSizedAndPositionedCorrectly(component, [
2308+
{tileStartRow: 0, height: 3 * component.getLineHeight() + 5},
2309+
{tileStartRow: 3, height: 3 * component.getLineHeight()},
2310+
{tileStartRow: 6, height: 3 * component.getLineHeight()}
2311+
])
2312+
2313+
marker.destroy()
2314+
await component.getNextUpdatePromise()
2315+
assertLinesAreAlignedWithLineNumbers(component)
2316+
assertTilesAreSizedAndPositionedCorrectly(component, [
2317+
{tileStartRow: 0, height: 3 * component.getLineHeight()},
2318+
{tileStartRow: 3, height: 3 * component.getLineHeight()},
2319+
{tileStartRow: 6, height: 3 * component.getLineHeight()}
2320+
])
2321+
})
2322+
23022323
it('removes block decorations whose markers are invalidated, and adds them back when they become valid again', async () => {
23032324
const editor = buildEditor({rowsPerTile: 3, autoHeight: false})
23042325
const {item, decoration, marker} = createBlockDecorationAtScreenRow(editor, 3, {height: 44, position: 'before', invalidate: 'touch'})

src/text-editor-component.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2506,7 +2506,7 @@ class TextEditorComponent {
25062506
didUpdateDisposable.dispose()
25072507
didDestroyDisposable.dispose()
25082508

2509-
if (marker.isValid()) {
2509+
if (wasValid) {
25102510
this.blockDecorationsToMeasure.delete(decoration)
25112511
this.heightsByBlockDecoration.delete(decoration)
25122512
this.blockDecorationsByElement.delete(element)

0 commit comments

Comments
 (0)