From 252d4572a150a4fb14260c6d89784f5da8459823 Mon Sep 17 00:00:00 2001 From: abe33 Date: Thu, 20 Oct 2016 23:03:47 +0200 Subject: [PATCH] :guardsman: Guard against destroyed editor in adapters and decorations manager Ref #489 --- lib/adapters/legacy-adapter.js | 4 ++++ lib/adapters/stable-adapter.js | 18 ++++++++++++++++++ lib/minimap.js | 2 ++ lib/mixins/decoration-management.js | 2 +- 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/adapters/legacy-adapter.js b/lib/adapters/legacy-adapter.js index 5cbf6808..e162c51d 100644 --- a/lib/adapters/legacy-adapter.js +++ b/lib/adapters/legacy-adapter.js @@ -72,4 +72,8 @@ export default class LegacyAdapter { if (this.useCache) { this.maxScrollTopCache = maxScrollTop } return maxScrollTop } + + editorDestroyed () { + return !this.textEditor || this.textEditor.isDestroyed() + } } diff --git a/lib/adapters/stable-adapter.js b/lib/adapters/stable-adapter.js index dfa56489..a5414624 100644 --- a/lib/adapters/stable-adapter.js +++ b/lib/adapters/stable-adapter.js @@ -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() @@ -38,6 +40,8 @@ export default class StableAdapter { } getScrollTop () { + if (this.editorDestroyed()) { return 0 } + if (this.useCache) { if (!this.scrollTopCache) { this.scrollTopCache = this.computeScrollTop() @@ -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() @@ -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() @@ -78,6 +88,8 @@ export default class StableAdapter { } getMaxScrollTop () { + if (this.editorDestroyed()) { return 0 } + if (this.maxScrollTopCache != null && this.useCache) { return this.maxScrollTopCache } @@ -95,4 +107,10 @@ export default class StableAdapter { return maxScrollTop } + + editorDestroyed () { + return !this.textEditor || + this.textEditor.isDestroyed() || + !this.textEditorElement.getModel() + } } diff --git a/lib/minimap.js b/lib/minimap.js index afe144fa..caf7e78a 100644 --- a/lib/minimap.js +++ b/lib/minimap.js @@ -950,4 +950,6 @@ export default class Minimap { */ clearCache () { this.adapter.clearCache() } + editorDestroyed () { this.adapter.editorDestroyed() } + } diff --git a/lib/mixins/decoration-management.js b/lib/mixins/decoration-management.js index ccbf122e..7b7349d5 100644 --- a/lib/mixins/decoration-management.js +++ b/lib/mixins/decoration-management.js @@ -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()