提交 8ebad589 编写于 作者: R rebornix

deprecate onDidChangeCells

上级 beab3b87
......@@ -13,9 +13,10 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur
import { ILogService } from 'vs/platform/log/common/log';
import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers';
import { INotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { NotebookCellTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookCellTextModel';
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
import { INotebookCellStatusBarService } from 'vs/workbench/contrib/notebook/common/notebookCellStatusBarService';
import { ACCESSIBLE_NOTEBOOK_DISPLAY_ORDER, CellEditType, CellKind, DisplayOrderKey, ICellEditOperation, ICellRange, IEditor, INotebookDocumentFilter, NotebookCellMetadata, NotebookCellOutputsSplice, NotebookDocumentMetadata, NOTEBOOK_DISPLAY_ORDER, TransientMetadata } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { ACCESSIBLE_NOTEBOOK_DISPLAY_ORDER, CellEditType, CellKind, DisplayOrderKey, ICellEditOperation, ICellRange, IEditor, IMainCellDto, INotebookDocumentFilter, NotebookCellMetadata, NotebookCellOutputsSplice, NotebookCellsChangeType, NotebookDocumentMetadata, NOTEBOOK_DISPLAY_ORDER, TransientMetadata } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { IMainNotebookController, INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { ExtHostContext, ExtHostNotebookShape, IExtHostContext, INotebookCellStatusBarEntryDto, INotebookDocumentsAndEditorsDelta, MainContext, MainThreadNotebookShape, NotebookEditorRevealType, NotebookExtensionDescription } from '../common/extHost.protocol';
......@@ -261,12 +262,44 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
notebookEditorAddedHandler(editor);
});
const cellToDto = (cell: NotebookCellTextModel): IMainCellDto => {
return {
handle: cell.handle,
uri: cell.uri,
source: cell.textBuffer.getLinesContent(),
eol: cell.textBuffer.getEOL(),
language: cell.language,
cellKind: cell.cellKind,
outputs: cell.outputs,
metadata: cell.metadata
};
};
const notebookDocumentAddedHandler = (doc: URI) => {
if (!this._editorEventListenersMapping.has(doc.toString())) {
const disposableStore = new DisposableStore();
const textModel = this._notebookService.getNotebookTextModel(doc);
disposableStore.add(textModel!.onDidModelChangeProxy(e => {
this._proxy.$acceptModelChanged(textModel!.uri, e, textModel!.isDirty);
const data =
e.kind === NotebookCellsChangeType.ModelChange || e.kind === NotebookCellsChangeType.Initialize
? {
kind: e.kind,
versionId: e.versionId,
changes: e.changes.map(diff => [diff[0], diff[1], diff[2].map(cell => cellToDto(cell as NotebookCellTextModel))] as [number, number, IMainCellDto[]])
}
: (
e.kind === NotebookCellsChangeType.Move
? {
kind: e.kind,
index: e.index,
length: e.length,
newIdx: e.newIdx,
versionId: e.versionId,
cells: e.cells.map(cell => cellToDto(cell as NotebookCellTextModel))
}
: e
);
this._proxy.$acceptModelChanged(textModel!.uri, data, textModel!.isDirty);
this._proxy.$acceptDocumentPropertiesChanged(doc, { metadata: null });
}));
......
......@@ -51,7 +51,7 @@ import { TunnelDto } from 'vs/workbench/api/common/extHostTunnelService';
import { TunnelOptions } from 'vs/platform/remote/common/tunnel';
import { Timeline, TimelineChangeEvent, TimelineOptions, TimelineProviderDescriptor, InternalTimelineOptions } from 'vs/workbench/contrib/timeline/common/timeline';
import { revive } from 'vs/base/common/marshalling';
import { IProcessedOutput, INotebookDisplayOrder, NotebookCellMetadata, NotebookDocumentMetadata, ICellEditOperation, NotebookCellsChangedEvent, NotebookDataDto, IMainCellDto, INotebookDocumentFilter, INotebookKernelInfoDto2, TransientMetadata, INotebookCellStatusBarEntry, ICellRange } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { IProcessedOutput, INotebookDisplayOrder, NotebookCellMetadata, NotebookDocumentMetadata, ICellEditOperation, NotebookCellsChangedEventDto, NotebookDataDto, IMainCellDto, INotebookDocumentFilter, INotebookKernelInfoDto2, TransientMetadata, INotebookCellStatusBarEntry, ICellRange } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { CallHierarchyItem } from 'vs/workbench/contrib/callHierarchy/common/callHierarchy';
import { Dto } from 'vs/base/common/types';
import { ISerializableEnvironmentVariableCollection } from 'vs/workbench/contrib/terminal/common/environmentVariable';
......@@ -1686,7 +1686,7 @@ export interface ExtHostNotebookShape {
$acceptDisplayOrder(displayOrder: INotebookDisplayOrder): void;
$acceptNotebookActiveKernelChange(event: { uri: UriComponents, providerHandle: number | undefined, kernelId: string | undefined }): void;
$onDidReceiveMessage(editorId: string, rendererId: string | undefined, message: unknown): void;
$acceptModelChanged(uriComponents: UriComponents, event: NotebookCellsChangedEvent, isDirty: boolean): void;
$acceptModelChanged(uriComponents: UriComponents, event: NotebookCellsChangedEventDto, isDirty: boolean): void;
$acceptModelSaved(uriComponents: UriComponents): void;
$acceptEditorPropertiesChanged(id: string, data: INotebookEditorPropertiesChangeData): void;
$acceptDocumentPropertiesChanged(uriComponents: UriComponents, data: INotebookDocumentPropertiesChangeData): void;
......
......@@ -22,7 +22,7 @@ import { IExtensionStoragePaths } from 'vs/workbench/api/common/extHostStoragePa
import * as typeConverters from 'vs/workbench/api/common/extHostTypeConverters';
import * as extHostTypes from 'vs/workbench/api/common/extHostTypes';
import { asWebviewUri, WebviewInitData } from 'vs/workbench/api/common/shared/webview';
import { addIdToOutput, CellEditType, CellOutputKind, CellStatusbarAlignment, CellUri, diff, ICellEditOperation, ICellReplaceEdit, IMainCellDto, INotebookCellStatusBarEntry, INotebookDisplayOrder, INotebookEditData, INotebookKernelInfoDto2, IProcessedOutput, NotebookCellMetadata, NotebookCellsChangedEvent, NotebookCellsChangeType, NotebookCellsSplice2, NotebookDataDto, notebookDocumentMetadataDefaults } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { addIdToOutput, CellEditType, CellOutputKind, CellStatusbarAlignment, CellUri, diff, ICellEditOperation, ICellReplaceEdit, IMainCellDto, INotebookCellStatusBarEntry, INotebookDisplayOrder, INotebookEditData, INotebookKernelInfoDto2, IProcessedOutput, NotebookCellMetadata, NotebookCellsChangedEventDto, NotebookCellsChangeType, NotebookCellsSplice2, NotebookDataDto, notebookDocumentMetadataDefaults } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import * as vscode from 'vscode';
import { Cache } from './cache';
import { ResourceMap } from 'vs/base/common/map';
......@@ -316,7 +316,7 @@ export class ExtHostNotebookDocument extends Disposable {
this._backup = undefined;
}
acceptModelChanged(event: NotebookCellsChangedEvent, isDirty: boolean): void {
acceptModelChanged(event: NotebookCellsChangedEventDto, isDirty: boolean): void {
this._versionId = event.versionId;
this._isDirty = isDirty;
if (event.kind === NotebookCellsChangeType.Initialize) {
......@@ -327,10 +327,6 @@ export class ExtHostNotebookDocument extends Disposable {
this._moveCell(event.index, event.newIdx);
} else if (event.kind === NotebookCellsChangeType.Output) {
this._setCellOutputs(event.index, event.outputs);
} else if (event.kind === NotebookCellsChangeType.CellClearOutput) {
this._clearCellOutputs(event.index);
} else if (event.kind === NotebookCellsChangeType.CellsClearOutput) {
this._clearAllCellOutputs();
} else if (event.kind === NotebookCellsChangeType.ChangeLanguage) {
this._changeCellLanguage(event.index, event.language);
} else if (event.kind === NotebookCellsChangeType.ChangeCellMetadata) {
......@@ -424,25 +420,6 @@ export class ExtHostNotebookDocument extends Disposable {
this._emitter.emitCellOutputsChange({ document: this.notebookDocument, cells: [cell.cell] });
}
private _clearCellOutputs(index: number): void {
const cell = this._cells[index].cell;
cell.outputs = [];
const event: vscode.NotebookCellOutputsChangeEvent = { document: this.notebookDocument, cells: [cell] };
this._emitter.emitCellOutputsChange(event);
}
private _clearAllCellOutputs(): void {
const modifedCells: vscode.NotebookCell[] = [];
this._cells.forEach(({ cell }) => {
if (cell.outputs.length !== 0) {
cell.outputs = [];
modifedCells.push(cell);
}
});
const event: vscode.NotebookCellOutputsChangeEvent = { document: this.notebookDocument, cells: modifedCells };
this._emitter.emitCellOutputsChange(event);
}
private _changeCellLanguage(index: number, language: string): void {
const cell = this._cells[index];
const event: vscode.NotebookCellLanguageChangeEvent = { document: this.notebookDocument, cell: cell.cell, language };
......@@ -1279,7 +1256,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
this._webviewComm.get(editorId)?.onDidReceiveMessage(forRendererType, message);
}
$acceptModelChanged(uriComponents: UriComponents, event: NotebookCellsChangedEvent, isDirty: boolean): void {
$acceptModelChanged(uriComponents: UriComponents, event: NotebookCellsChangedEventDto, isDirty: boolean): void {
const document = this._documents.get(URI.revive(uriComponents));
if (document) {
document.acceptModelChanged(event, isDirty);
......
......@@ -14,6 +14,7 @@ import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/no
import { FileService } from 'vs/platform/files/common/fileService';
import { IFileService } from 'vs/platform/files/common/files';
import { URI } from 'vs/base/common/uri';
import { NotebookCellsChangeType } from 'vs/workbench/contrib/notebook/common/notebookCommon';
export class SCMController extends Disposable implements INotebookEditorContribution {
static id: string = 'workbench.notebook.findController';
......@@ -47,8 +48,10 @@ export class SCMController extends Disposable implements INotebookEditorContribu
this.update();
}));
this._localDisposable.add(this._notebookEditor.textModel.onDidChangeCells(() => {
this.update();
this._localDisposable.add(this._notebookEditor.textModel.onDidModelChangeProxy((e) => {
if (e.kind === NotebookCellsChangeType.ModelChange) {
this.update();
}
}));
}
}));
......
......@@ -23,7 +23,7 @@ import { NotebookEventDispatcher, NotebookMetadataChangedEvent } from 'vs/workbe
import { CellFoldingState, EditorFoldingStateDelegate } from 'vs/workbench/contrib/notebook/browser/contrib/fold/foldingModel';
import { MarkdownCellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/markdownCellViewModel';
import { NotebookCellTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookCellTextModel';
import { CellKind, NotebookCellMetadata, INotebookSearchOptions, ICellRange, NotebookCellsChangeType } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { CellKind, NotebookCellMetadata, INotebookSearchOptions, ICellRange, NotebookCellsChangeType, ICell, NotebookCellTextModelSplice } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { FoldingRegions } from 'vs/editor/contrib/folding/foldingRanges';
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
import { MarkdownRenderer } from 'vs/workbench/contrib/notebook/browser/view/renderers/mdRenderer';
......@@ -251,8 +251,8 @@ export class NotebookViewModel extends Disposable implements EditorFoldingStateD
this.id = '$notebookViewModel' + MODEL_ID;
this._instanceId = strings.singleLetterHash(MODEL_ID);
this._register(this._notebook.onDidChangeCells(e => {
const diffs = e.splices.map(splice => {
const compute = (changes: NotebookCellTextModelSplice<ICell>[], synchronous: boolean) => {
const diffs = changes.map(splice => {
return [splice[0], splice[1], splice[2].map(cell => {
return createCellViewModel(this._instantiationService, this, cell as NotebookCellTextModel);
})] as [number, number, CellViewModel[]];
......@@ -275,7 +275,7 @@ export class NotebookViewModel extends Disposable implements EditorFoldingStateD
});
this._onDidChangeViewCells.fire({
synchronous: e.synchronous,
synchronous: synchronous,
splices: diffs
});
......@@ -306,6 +306,21 @@ export class NotebookViewModel extends Disposable implements EditorFoldingStateD
}
this.selectionHandles = endSelectionHandles;
};
this._register(this._notebook.onDidModelChangeProxy(e => {
let changes: NotebookCellTextModelSplice<ICell>[] = [];
if (e.kind === NotebookCellsChangeType.ModelChange || e.kind === NotebookCellsChangeType.Initialize) {
changes = e.changes;
compute(changes, e.synchronous);
return;
} else if (e.kind === NotebookCellsChangeType.Move) {
compute([[e.index, e.length, []]], e.synchronous);
compute([[e.newIdx, 0, e.cells]], e.synchronous);
} else {
return;
}
}));
this._register(this._notebook.onDidChangeContent(e => {
......
......@@ -8,7 +8,7 @@ import { Emitter, Event } from 'vs/base/common/event';
import { Disposable, IDisposable } from 'vs/base/common/lifecycle';
import { URI } from 'vs/base/common/uri';
import { NotebookCellTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookCellTextModel';
import { INotebookTextModel, NotebookCellOutputsSplice, NotebookCellTextModelSplice, NotebookDocumentMetadata, NotebookCellMetadata, ICellEditOperation, CellEditType, CellUri, NotebookCellsChangedEvent, CellKind, IProcessedOutput, notebookDocumentMetadataDefaults, diff, NotebookCellsChangeType, ICellDto2, IMainCellDto, TransientOptions } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { INotebookTextModel, NotebookCellOutputsSplice, NotebookCellTextModelSplice, NotebookDocumentMetadata, NotebookCellMetadata, ICellEditOperation, CellEditType, CellUri, CellKind, IProcessedOutput, notebookDocumentMetadataDefaults, diff, NotebookCellsChangeType, ICellDto2, TransientOptions, NotebookTextModelChangedEvent } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { ITextSnapshot } from 'vs/editor/common/model';
import { IUndoRedoService, UndoRedoElementType, IUndoRedoElement, IResourceUndoRedoElement } from 'vs/platform/undoRedo/common/undoRedo';
import { InsertCellEdit, DeleteCellEdit, MoveCellEdit, SpliceCellsEdit, CellMetadataEdit } from 'vs/workbench/contrib/notebook/common/model/cellEdit';
......@@ -109,8 +109,7 @@ export class NotebookOperationManager {
class DelayedEmitter {
constructor(
private readonly _onDidChangeContentEmitter: Emitter<NotebookCellsChangeType | undefined>,
private readonly _onDidChangeCells: Emitter<{ synchronous: boolean, splices: NotebookCellTextModelSplice[] }>,
private readonly _onDidModelChangeProxy: Emitter<NotebookCellsChangedEvent>,
private readonly _onDidModelChangeProxy: Emitter<NotebookTextModelChangedEvent>,
private readonly _increaseVersion: () => void,
private readonly _textModel: NotebookTextModel
......@@ -121,8 +120,8 @@ class DelayedEmitter {
emit(data: {
triggerDirty: { value: boolean } | undefined,
contentChange: { value: NotebookCellsChangeType | undefined } | undefined,
cellsChange: { value: { synchronous: boolean, splices: NotebookCellTextModelSplice[] } } | undefined,
modelProxyChange: { value: NotebookCellsChangedEvent } | undefined,
cellsChange: { value: { synchronous: boolean, splices: NotebookCellTextModelSplice<NotebookCellTextModel>[] } } | undefined,
modelProxyChange: { value: NotebookTextModelChangedEvent } | undefined,
}) {
this._increaseVersion();
......@@ -134,10 +133,6 @@ class DelayedEmitter {
this._onDidChangeContentEmitter.fire(data.contentChange.value);
}
if (data.cellsChange) {
this._onDidChangeCells.fire(data.cellsChange.value);
}
if (data.modelProxyChange) {
this._onDidModelChangeProxy.fire(
{
......@@ -158,13 +153,10 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
private _dirty = false;
protected readonly _onDidChangeDirty = this._register(new Emitter<void>());
readonly onDidChangeDirty = this._onDidChangeDirty.event;
private readonly _onDidChangeCells = this._register(new Emitter<{ synchronous: boolean, splices: NotebookCellTextModelSplice[] }>());
get onDidChangeCells() { return this._onDidChangeCells.event; }
private readonly _emitSelections = this._register(new Emitter<number[]>());
get emitSelections() { return this._emitSelections.event; }
private _onDidModelChangeProxy = this._register(new Emitter<NotebookCellsChangedEvent>());
get onDidModelChangeProxy(): Event<NotebookCellsChangedEvent> { return this._onDidModelChangeProxy.event; }
private _onDidModelChangeProxy = this._register(new Emitter<NotebookTextModelChangedEvent>());
get onDidModelChangeProxy(): Event<NotebookTextModelChangedEvent> { return this._onDidModelChangeProxy.event; }
private _onDidChangeContent = this._register(new Emitter<NotebookCellsChangeType | undefined>());
onDidChangeContent: Event<NotebookCellsChangeType | undefined> = this._onDidChangeContent.event;
private _mapping: Map<number, NotebookCellTextModel> = new Map();
......@@ -212,7 +204,6 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
this._operationManager = new NotebookOperationManager(this._undoService, uri);
this._eventEmitter = new DelayedEmitter(
this._onDidChangeContent,
this._onDidChangeCells,
this._onDidModelChangeProxy,
() => { this._increaseVersionId(); },
this
......@@ -385,16 +376,8 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
value: {
kind: NotebookCellsChangeType.ModelChange,
versionId: this._versionId,
changes: diffs.map(diff => [diff[0], diff[1], diff[2].map(cell => ({
handle: cell.handle,
uri: cell.uri,
source: cell.textBuffer.getLinesContent(),
eol: cell.textBuffer.getEOL(),
language: cell.language,
cellKind: cell.cellKind,
outputs: cell.outputs,
metadata: cell.metadata
}))] as [number, number, IMainCellDto[]])
changes: diffs,
synchronous
}
}
});
......@@ -469,17 +452,9 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
[[
0,
0,
[{
handle: cell.handle,
uri: cell.uri,
source: cell.textBuffer.getLinesContent(),
eol: cell.textBuffer.getEOL(),
language: cell.language,
cellKind: cell.cellKind,
outputs: cell.outputs,
metadata: cell.metadata
}]
]]
[cell]
]],
synchronous: true
});
return;
......@@ -511,21 +486,11 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
[[
index,
0,
cells.map(cell => ({
handle: cell.handle,
uri: cell.uri,
source: cell.textBuffer.getLinesContent(),
eol: cell.textBuffer.getEOL(),
language: cell.language,
cellKind: cell.cellKind,
outputs: cell.outputs,
metadata: cell.metadata
}))
]]
cells
]],
synchronous
});
this._onDidChangeCells.fire({ synchronous: synchronous, splices: [[index, 0, cells]] });
return;
}
......@@ -542,8 +507,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
this._onDidChangeContent.fire(NotebookCellsChangeType.ModelChange);
this._increaseVersionId();
this._onDidModelChangeProxy.fire({ kind: NotebookCellsChangeType.ModelChange, versionId: this._versionId, changes: [[index, count, []]] });
this._onDidChangeCells.fire({ synchronous: synchronous, splices: [[index, 1, []]] });
this._onDidModelChangeProxy.fire({ kind: NotebookCellsChangeType.ModelChange, versionId: this._versionId, changes: [[index, count, []]], synchronous });
}
private _isCellMetadataChanged(a: NotebookCellMetadata, b: NotebookCellMetadata) {
......@@ -595,7 +559,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
contentChange: { value: NotebookCellsChangeType.ChangeCellMetadata },
cellsChange: undefined,
modelProxyChange: {
value: { kind: NotebookCellsChangeType.ChangeCellMetadata, versionId: this._versionId, index: this.cells.indexOf(cell), metadata: cell.metadata }
value: { kind: NotebookCellsChangeType.ChangeCellMetadata, versionId: this._versionId, index: this.cells.indexOf(cell), metadata: cell.metadata, synchronous: true }
}
});
}
......@@ -615,7 +579,8 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
kind: NotebookCellsChangeType.Output,
versionId: this.versionId,
index: this.cells.indexOf(cell),
outputs: cell.outputs ?? []
outputs: cell.outputs ?? [],
synchronous: true
}
}
});
......@@ -637,7 +602,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
cell.language = languageId;
this._increaseVersionId();
this._onDidModelChangeProxy.fire({ kind: NotebookCellsChangeType.ChangeLanguage, versionId: this._versionId, index: this.cells.indexOf(cell), language: languageId });
this._onDidModelChangeProxy.fire({ kind: NotebookCellsChangeType.ChangeLanguage, versionId: this._versionId, index: this.cells.indexOf(cell), language: languageId, synchronous: true });
}
}
......@@ -674,7 +639,6 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
}
moveCellToIdx(index: number, length: number, newIdx: number, synchronous: boolean, pushedToUndoStack: boolean, beforeSelections: number[] | undefined, endSelections: number[] | undefined): boolean {
const cells = this.cells.slice(index, index + length);
if (pushedToUndoStack) {
this._operationManager.pushEditOperation(new MoveCellEdit(this.uri, index, length, newIdx, {
moveCell: (fromIndex: number, length: number, toIndex: number, beforeSelections: number[] | undefined, endSelections: number[] | undefined) => {
......@@ -694,13 +658,13 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
this._onDidChangeContent.fire(NotebookCellsChangeType.Move);
this._increaseVersionId();
this._onDidModelChangeProxy.fire({ kind: NotebookCellsChangeType.Move, versionId: this._versionId, index, newIdx });
this._onDidModelChangeProxy.fire({ kind: NotebookCellsChangeType.Move, versionId: this._versionId, index, length, newIdx, cells, synchronous });
}
// todo, we can't emit this change as it will create a new view model and that will hold
// a new reference to the document, thus
this._onDidChangeCells.fire({ synchronous: synchronous, splices: [[index, length, []]] });
this._onDidChangeCells.fire({ synchronous: synchronous, splices: [[newIdx, 0, cells]] });
// this._onDidChangeCells.fire({ synchronous: synchronous, splices: [[index, length, []]] });
// this._onDidChangeCells.fire({ synchronous: synchronous, splices: [[newIdx, 0, cells]] });
if (endSelections) {
this._emitSelections.fire(endSelections);
}
......
......@@ -277,7 +277,6 @@ export interface INotebookTextModel {
readonly versionId: number;
languages: string[];
cells: ICell[];
onDidChangeCells?: Event<{ synchronous: boolean, splices: NotebookCellTextModelSplice[] }>;
onDidChangeContent: Event<NotebookCellsChangeType | undefined>;
onWillDispose(listener: () => void): IDisposable;
}
......@@ -312,10 +311,10 @@ export type IRenderOutput = IRenderNoOutput | IInsetRenderOutput;
export const outputHasDynamicHeight = (o: IRenderOutput) => o.type !== RenderOutputType.Extension && o.hasDynamicHeight;
export type NotebookCellTextModelSplice = [
export type NotebookCellTextModelSplice<T> = [
number /* start */,
number,
ICell[]
T[]
];
export type NotebookCellOutputsSplice = [
......@@ -354,9 +353,9 @@ export enum NotebookCellsChangeType {
ChangeDocumentMetadata = 10
}
export interface NotebookCellsInitializeEvent {
export interface NotebookCellsInitializeEvent<T> {
readonly kind: NotebookCellsChangeType.Initialize;
readonly changes: NotebookCellsSplice2[];
readonly changes: NotebookCellTextModelSplice<T>[];
readonly versionId: number;
}
......@@ -365,16 +364,18 @@ export interface NotebookCellContentChangeEvent {
readonly versionId: number;
}
export interface NotebookCellsModelChangedEvent {
export interface NotebookCellsModelChangedEvent<T> {
readonly kind: NotebookCellsChangeType.ModelChange;
readonly changes: NotebookCellsSplice2[];
readonly changes: NotebookCellTextModelSplice<T>[];
readonly versionId: number;
}
export interface NotebookCellsModelMoveEvent {
export interface NotebookCellsModelMoveEvent<T> {
readonly kind: NotebookCellsChangeType.Move;
readonly index: number;
readonly length: number;
readonly newIdx: number;
readonly cells: T[];
readonly versionId: number;
}
......@@ -385,17 +386,6 @@ export interface NotebookOutputChangedEvent {
readonly outputs: IProcessedOutput[];
}
export interface NotebookCellClearOutputEvent {
readonly kind: NotebookCellsChangeType.CellClearOutput;
readonly index: number;
readonly versionId: number;
}
export interface NotebookCellsClearOutputEvent {
readonly kind: NotebookCellsChangeType.CellsClearOutput;
readonly versionId: number;
}
export interface NotebookCellsChangeLanguageEvent {
readonly kind: NotebookCellsChangeType.ChangeLanguage;
readonly versionId: number;
......@@ -416,7 +406,8 @@ export interface NotebookDocumentChangeMetadataEvent {
readonly metadata: NotebookDocumentMetadata | undefined;
}
export type NotebookCellsChangedEvent = NotebookCellsInitializeEvent | NotebookDocumentChangeMetadataEvent | NotebookCellContentChangeEvent | NotebookCellsModelChangedEvent | NotebookCellsModelMoveEvent | NotebookOutputChangedEvent | NotebookCellClearOutputEvent | NotebookCellsClearOutputEvent | NotebookCellsChangeLanguageEvent | NotebookCellsChangeMetadataEvent;
export type NotebookCellsChangedEventDto = NotebookCellsInitializeEvent<IMainCellDto> | NotebookDocumentChangeMetadataEvent | NotebookCellContentChangeEvent | NotebookCellsModelChangedEvent<IMainCellDto> | NotebookCellsModelMoveEvent<IMainCellDto> | NotebookOutputChangedEvent | NotebookCellsChangeLanguageEvent | NotebookCellsChangeMetadataEvent;
export type NotebookTextModelChangedEvent = (NotebookCellsInitializeEvent<ICell> | NotebookDocumentChangeMetadataEvent | NotebookCellContentChangeEvent | NotebookCellsModelChangedEvent<ICell> | NotebookCellsModelMoveEvent<ICell> | NotebookOutputChangedEvent | NotebookCellsChangeLanguageEvent | NotebookCellsChangeMetadataEvent) & { synchronous: boolean; };
export const enum CellEditType {
Replace = 1,
......
......@@ -69,18 +69,18 @@ suite('NotebookViewModel', () => {
['//c', 'javascript', CellKind.Code, [], { editable: true }],
],
(editor, viewModel) => {
viewModel.moveCellToIdx(0, 1, 0, false);
viewModel.moveCellToIdx(0, 1, 0, true);
// no-op
assert.equal(viewModel.viewCells[0].getText(), '//a');
assert.equal(viewModel.viewCells[1].getText(), '//b');
viewModel.moveCellToIdx(0, 1, 1, false);
viewModel.moveCellToIdx(0, 1, 1, true);
// b, a, c
assert.equal(viewModel.viewCells[0].getText(), '//b');
assert.equal(viewModel.viewCells[1].getText(), '//a');
assert.equal(viewModel.viewCells[2].getText(), '//c');
viewModel.moveCellToIdx(0, 1, 2, false);
viewModel.moveCellToIdx(0, 1, 2, true);
// a, c, b
assert.equal(viewModel.viewCells[0].getText(), '//a');
assert.equal(viewModel.viewCells[1].getText(), '//c');
......@@ -100,12 +100,12 @@ suite('NotebookViewModel', () => {
['//c', 'javascript', CellKind.Code, [], { editable: true }],
],
(editor, viewModel) => {
viewModel.moveCellToIdx(1, 1, 0, false);
viewModel.moveCellToIdx(1, 1, 0, true);
// b, a, c
assert.equal(viewModel.viewCells[0].getText(), '//b');
assert.equal(viewModel.viewCells[1].getText(), '//a');
viewModel.moveCellToIdx(2, 1, 0, false);
viewModel.moveCellToIdx(2, 1, 0, true);
// c, b, a
assert.equal(viewModel.viewCells[0].getText(), '//c');
assert.equal(viewModel.viewCells[1].getText(), '//b');
......
......@@ -337,7 +337,7 @@ export class NotebookEditorTestModel extends EditorModel implements INotebookEdi
) {
super();
if (_notebook && _notebook.onDidChangeCells) {
if (_notebook && _notebook.onDidChangeContent) {
this._register(_notebook.onDidChangeContent(() => {
this._dirty = true;
this._onDidChangeDirty.fire();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册