Skip to content

Commit e794bb5

Browse files
committed
fix diff editor throwing errors after being destroyed
1 parent 60fb34b commit e794bb5

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

src/ext/diff/base_diff_view.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,13 +435,14 @@ class BaseDiffView {
435435
*/
436436
$initWidgets(editor) {
437437
var session = editor.session;
438+
if (!session) return;
438439
if (!session.widgetManager) {
439440
session.widgetManager = new LineWidgets(session);
440441
session.widgetManager.attach(editor);
441442
}
442-
editor.session.lineWidgets = [];
443-
editor.session.widgetManager.lineWidgets = [];
444-
editor.session.$resetRowCache(0);
443+
session.lineWidgets = [];
444+
session.widgetManager.lineWidgets = [];
445+
session.$resetRowCache(0);
445446
}
446447

447448
/**
@@ -598,7 +599,7 @@ class BaseDiffView {
598599
if (this.savedOptionsB &&this.savedOptionsB.customScrollbar) {
599600
this.$resetDecorators(this.editorB.renderer);
600601
}
601-
602+
clearTimeout(this.$onInputTimer);
602603
}
603604

604605
$removeLineWidgets(session) {

src/ext/diff/inline_diff_view.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class InlineDiffView extends BaseDiffView {
140140

141141
selectEditor(editor) {
142142
if (editor == this.activeEditor) {
143-
this.otherEditor.selection.clearSelection();
143+
this.otherEditor.selection && this.otherEditor.selection.clearSelection();
144144
this.activeEditor.textInput.setHost(this.activeEditor);
145145
this.activeEditor.setStyle("ace_diff_other", false);
146146
this.cursorLayer.element.remove();
@@ -153,7 +153,7 @@ class InlineDiffView extends BaseDiffView {
153153
this.activeEditor.renderer.$markerBack.element.classList.remove("ace_hidden_marker-layer");
154154
this.removeBracketHighlight(this.otherEditor);
155155
} else {
156-
this.activeEditor.selection.clearSelection();
156+
this.activeEditor.selection && this.activeEditor.selection.clearSelection();
157157
this.activeEditor.textInput.setHost(this.otherEditor);
158158
this.activeEditor.setStyle("ace_diff_other");
159159
this.activeEditor.renderer.$cursorLayer.element.parentNode.appendChild(
@@ -174,7 +174,7 @@ class InlineDiffView extends BaseDiffView {
174174

175175
removeBracketHighlight(editor) {
176176
var session = editor.session;
177-
if (session.$bracketHighlight) {
177+
if (session && session.$bracketHighlight) {
178178
session.$bracketHighlight.markerIds.forEach(function(id) {
179179
session.removeMarker(id);
180180
});
@@ -312,6 +312,7 @@ class InlineDiffView extends BaseDiffView {
312312
}
313313

314314
$detachSessionHandlers(editor, marker) {
315+
if (!editor.session) return;
315316
editor.session.removeMarker(marker.id);
316317
editor.selection.off("changeCursor", this.onSelect);
317318
editor.selection.off("changeSelection", this.onSelect);

0 commit comments

Comments
 (0)