Skip to content

Commit

Permalink
Don't throw when destroying block decorations inside marker change event
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio Scandurra committed Oct 11, 2017
1 parent 2ca2dfd commit 7853e3c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
18 changes: 18 additions & 0 deletions spec/text-editor-component-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2541,6 +2541,24 @@ describe('TextEditorComponent', () => {
])
})

it('does not throw exceptions when destroying a block decoration inside a marker change event (regression)', async () => {
const {editor, component} = buildComponent({rowsPerTile: 3})

const marker = editor.markScreenPosition([2, 0])
marker.onDidChange(() => { marker.destroy() })
const item = document.createElement('div')
editor.decorateMarker(marker, {type: 'block', item})

await component.getNextUpdatePromise()
expect(item.nextSibling).toBe(lineNodeForScreenRow(component, 2))

marker.setBufferRange([[0, 0], [0, 0]])
expect(marker.isDestroyed()).toBe(true)

await component.getNextUpdatePromise()
expect(item.parentElement).toBeNull()
})

it('does not attempt to render block decorations located outside the visible range', async () => {
const {editor, component} = buildComponent({autoHeight: false, rowsPerTile: 2})
await setEditorHeightInLines(component, 2)
Expand Down
1 change: 1 addition & 0 deletions src/text-editor-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -2523,6 +2523,7 @@ class TextEditorComponent {
didDestroyDisposable.dispose()

if (wasValid) {
wasValid = false
this.blockDecorationsToMeasure.delete(decoration)
this.heightsByBlockDecoration.delete(decoration)
this.blockDecorationsByElement.delete(element)
Expand Down

0 comments on commit 7853e3c

Please sign in to comment.