mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-18 22:29:56 +01:00
lifecycle & disable scm notebook
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user