lifecycle & disable scm notebook

This commit is contained in:
rebornix
2020-08-25 08:34:22 -07:00
parent 81204145b5
commit 6aab9f199e
5 changed files with 47 additions and 32 deletions
@@ -4,14 +4,12 @@
*--------------------------------------------------------------------------------------------*/
import { Disposable, DisposableStore } from 'vs/base/common/lifecycle';
import { INotebookEditorContribution, INotebookEditor, INotebookDeltaDecoration } from '../../notebookBrowser';
import { INotebookEditorContribution, INotebookEditor } from '../../notebookBrowser';
import { registerNotebookContribution } from '../../notebookEditorExtensions';
import { ISCMService } from 'vs/workbench/contrib/scm/common/scm';
import { createProviderComparer } from 'vs/workbench/contrib/scm/browser/dirtydiffDecorator';
import { first, ThrottledDelayer } from 'vs/base/common/async';
import { INotebookService } from '../../../common/notebookService';
import { LcsDiff } from 'vs/base/common/diff/diff';
import { CellSequence } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
import { FileService } from 'vs/platform/files/common/fileService';
import { IFileService } from 'vs/platform/files/common/files';
@@ -40,6 +38,7 @@ export class SCMController extends Disposable implements INotebookEditorContribu
if (!this._notebookEditor.isEmbedded) {
this._register(this._notebookEditor.onDidChangeModel(() => {
this._localDisposable.clear();
this._originalResourceDisposableStore.clear();
this._diffDelayer.cancel();
this.update();
@@ -54,6 +53,11 @@ export class SCMController extends Disposable implements INotebookEditorContribu
}
}));
this._register(this._notebookEditor.onWillDispose(() => {
this._localDisposable.clear();
this._originalResourceDisposableStore.clear();
}));
this.update();
}
}
@@ -87,6 +91,12 @@ export class SCMController extends Disposable implements INotebookEditorContribu
}));
const originalDocument = await this._notebookService.resolveNotebook(viewType, result, false);
this._originalResourceDisposableStore.add({
dispose: () => {
this._originalDocument?.dispose();
this._originalDocument = undefined;
}
});
this._originalDocument = originalDocument;
}
@@ -115,37 +125,37 @@ export class SCMController extends Disposable implements INotebookEditorContribu
return;
}
const diff = new LcsDiff(new CellSequence(this._originalDocument), new CellSequence(modifiedDocument));
const diffResult = diff.ComputeDiff(false);
// const diff = new LcsDiff(new CellSequence(this._originalDocument), new CellSequence(modifiedDocument));
// const diffResult = diff.ComputeDiff(false);
const decorations: INotebookDeltaDecoration[] = [];
diffResult.changes.forEach(change => {
if (change.originalLength === 0) {
// doesn't exist in original
for (let i = 0; i < change.modifiedLength; i++) {
decorations.push({
handle: modifiedDocument.cells[change.modifiedStart + i].handle,
options: { gutterClassName: 'nb-gutter-cell-inserted' }
});
}
} else {
if (change.modifiedLength === 0) {
// diff.deleteCount
// removed from original
} else {
// modification
for (let i = 0; i < change.modifiedLength; i++) {
decorations.push({
handle: modifiedDocument.cells[change.modifiedStart + i].handle,
options: { gutterClassName: 'nb-gutter-cell-changed' }
});
}
}
}
});
// const decorations: INotebookDeltaDecoration[] = [];
// diffResult.changes.forEach(change => {
// if (change.originalLength === 0) {
// // doesn't exist in original
// for (let i = 0; i < change.modifiedLength; i++) {
// decorations.push({
// handle: modifiedDocument.cells[change.modifiedStart + i].handle,
// options: { gutterClassName: 'nb-gutter-cell-inserted' }
// });
// }
// } else {
// if (change.modifiedLength === 0) {
// // diff.deleteCount
// // removed from original
// } else {
// // modification
// for (let i = 0; i < change.modifiedLength; i++) {
// decorations.push({
// handle: modifiedDocument.cells[change.modifiedStart + i].handle,
// options: { gutterClassName: 'nb-gutter-cell-changed' }
// });
// }
// }
// }
// });
this._lastDecorationId = this._notebookEditor.deltaCellDecorations(this._lastDecorationId, decorations);
// this._lastDecorationId = this._notebookEditor.deltaCellDecorations(this._lastDecorationId, decorations);
});
}
@@ -56,7 +56,7 @@ import 'vs/workbench/contrib/notebook/browser/contrib/format/formatting';
import 'vs/workbench/contrib/notebook/browser/contrib/toc/tocProvider';
import 'vs/workbench/contrib/notebook/browser/contrib/marker/markerProvider';
import 'vs/workbench/contrib/notebook/browser/contrib/status/editorStatus';
import 'vs/workbench/contrib/notebook/browser/contrib/scm/scm';
// import 'vs/workbench/contrib/notebook/browser/contrib/scm/scm';
// Output renderers registration
@@ -224,6 +224,7 @@ export interface INotebookEditor extends IEditor {
readonly onDidChangeKernel: Event<void>;
readonly onDidChangeActiveCell: Event<void>;
readonly onDidScroll: Event<ScrollEvent>;
readonly onWillDispose: Event<void>;
isDisposed: boolean;
@@ -101,6 +101,8 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
public readonly onDidFocus = this._onDidFocusEmitter.event;
private readonly _onWillScroll = this._register(new Emitter<ScrollEvent>());
public readonly onWillScroll: Event<ScrollEvent> = this._onWillScroll.event;
private readonly _onWillDispose = this._register(new Emitter<void>());
public readonly onWillDispose: Event<void> = this._onWillDispose.event;
set scrollTop(top: number) {
if (this._list) {
@@ -1672,6 +1674,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
dispose() {
this._isDisposed = true;
this._onWillDispose.fire();
// dispose webview first
this._webview?.dispose();
@@ -77,6 +77,7 @@ export class TestNotebookEditor implements INotebookEditor {
onDidChangeAvailableKernels: Event<void> = new Emitter<void>().event;
onDidChangeActiveCell: Event<void> = new Emitter<void>().event;
onDidScroll = new Emitter<ScrollEvent>().event;
onWillDispose = new Emitter<void>().event;
uri?: URI | undefined;
textModel?: NotebookTextModel | undefined;