Skip to content

Commit 132a7e6

Browse files
authored
Dispose overview rulers when the diff editor model is set (microsoft#152182)
Fixes microsoft#152176: Dispose overview rulers when the diff editor model is set
1 parent e07cc2a commit 132a7e6

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

src/vs/editor/browser/widget/diffEditorWidget.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import 'vs/css!./media/diffEditor';
77
import * as nls from 'vs/nls';
88
import * as dom from 'vs/base/browser/dom';
9+
import * as assert from 'vs/base/common/assert';
910
import { FastDomNode, createFastDomNode } from 'vs/base/browser/fastDomNode';
1011
import { ISashEvent, IVerticalSashLayoutProvider, Sash, SashState, Orientation } from 'vs/base/browser/ui/sash/sash';
1112
import { RunOnceScheduler } from 'vs/base/common/async';
@@ -429,23 +430,29 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
429430
return result;
430431
}
431432

432-
private _recreateOverviewRulers(): void {
433-
if (!this._options.renderOverviewRuler) {
434-
return;
435-
}
436-
433+
private _disposeOverviewRulers(): void {
437434
if (this._originalOverviewRuler) {
438435
this._overviewDomElement.removeChild(this._originalOverviewRuler.getDomNode());
439436
this._originalOverviewRuler.dispose();
437+
this._originalOverviewRuler = null;
440438
}
441-
if (this._originalEditor.hasModel()) {
442-
this._originalOverviewRuler = this._originalEditor.createOverviewRuler('original diffOverviewRuler')!;
443-
this._overviewDomElement.appendChild(this._originalOverviewRuler.getDomNode());
444-
}
445-
446439
if (this._modifiedOverviewRuler) {
447440
this._overviewDomElement.removeChild(this._modifiedOverviewRuler.getDomNode());
448441
this._modifiedOverviewRuler.dispose();
442+
this._modifiedOverviewRuler = null;
443+
}
444+
}
445+
446+
private _createOverviewRulers(): void {
447+
if (!this._options.renderOverviewRuler) {
448+
return;
449+
}
450+
451+
assert.ok(!this._originalOverviewRuler && !this._modifiedOverviewRuler);
452+
453+
if (this._originalEditor.hasModel()) {
454+
this._originalOverviewRuler = this._originalEditor.createOverviewRuler('original diffOverviewRuler')!;
455+
this._overviewDomElement.appendChild(this._originalOverviewRuler.getDomNode());
449456
}
450457
if (this._modifiedEditor.hasModel()) {
451458
this._modifiedOverviewRuler = this._modifiedEditor.createOverviewRuler('modified diffOverviewRuler')!;
@@ -794,6 +801,8 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
794801
// Remove all view zones & decorations
795802
this._cleanViewZonesAndDecorations();
796803

804+
this._disposeOverviewRulers();
805+
797806
// Update code editor models
798807
this._originalEditor.setModel(model ? model.original : null);
799808
this._modifiedEditor.setModel(model ? model.modified : null);
@@ -812,7 +821,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
812821
this._setState(editorBrowser.DiffEditorState.Idle);
813822

814823
if (model) {
815-
this._recreateOverviewRulers();
824+
this._createOverviewRulers();
816825

817826
// Begin comparing
818827
this._beginUpdateDecorations();

0 commit comments

Comments
 (0)