Skip to content

Commit

Permalink
💂‍♂️ Guard against destroyed editor in adapters and decorations manager
Browse files Browse the repository at this point in the history
Ref #489
  • Loading branch information
abe33 committed Oct 20, 2016
1 parent 73b9917 commit 252d457
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/adapters/legacy-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,8 @@ export default class LegacyAdapter {
if (this.useCache) { this.maxScrollTopCache = maxScrollTop }
return maxScrollTop
}

editorDestroyed () {
return !this.textEditor || this.textEditor.isDestroyed()
}
}
18 changes: 18 additions & 0 deletions lib/adapters/stable-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export default class StableAdapter {
}

getHeight () {
if (this.editorDestroyed()) { return 0 }

if (this.useCache) {
if (!this.heightCache) {
this.heightCache = this.textEditorElement.getHeight()
Expand All @@ -38,6 +40,8 @@ export default class StableAdapter {
}

getScrollTop () {
if (this.editorDestroyed()) { return 0 }

if (this.useCache) {
if (!this.scrollTopCache) {
this.scrollTopCache = this.computeScrollTop()
Expand All @@ -48,6 +52,8 @@ export default class StableAdapter {
}

computeScrollTop () {
if (this.editorDestroyed()) { return 0 }

const scrollTop = this.textEditorElement.getScrollTop()
const lineHeight = this.textEditor.getLineHeightInPixels()
let firstRow = this.textEditorElement.getFirstVisibleScreenRow()
Expand All @@ -64,10 +70,14 @@ export default class StableAdapter {
}

setScrollTop (scrollTop) {
if (this.editorDestroyed()) { return }

this.textEditorElement.setScrollTop(scrollTop)
}

getScrollLeft () {
if (this.editorDestroyed()) { return 0 }

if (this.useCache) {
if (!this.scrollLeftCache) {
this.scrollLeftCache = this.textEditorElement.getScrollLeft()
Expand All @@ -78,6 +88,8 @@ export default class StableAdapter {
}

getMaxScrollTop () {
if (this.editorDestroyed()) { return 0 }

if (this.maxScrollTopCache != null && this.useCache) {
return this.maxScrollTopCache
}
Expand All @@ -95,4 +107,10 @@ export default class StableAdapter {

return maxScrollTop
}

editorDestroyed () {
return !this.textEditor ||
this.textEditor.isDestroyed() ||
!this.textEditorElement.getModel()
}
}
2 changes: 2 additions & 0 deletions lib/minimap.js
Original file line number Diff line number Diff line change
Expand Up @@ -950,4 +950,6 @@ export default class Minimap {
*/
clearCache () { this.adapter.clearCache() }

editorDestroyed () { this.adapter.editorDestroyed() }

}
2 changes: 1 addition & 1 deletion lib/mixins/decoration-management.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ export default class DecorationManagement extends Mixin {
* @access private
*/
emitDecorationChanges (type, decoration) {
if (!this.textEditor || this.textEditor.isDestroyed()) { return }
if (this.editorDestroyed()) { return }

this.invalidateDecorationForScreenRowsCache()

Expand Down

0 comments on commit 252d457

Please sign in to comment.