提交 bb7b1ef6 编写于 作者: R rebornix

Use the same undo redo group for notebook editing

上级 7b6723e7
......@@ -164,7 +164,7 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
return false;
}
this._notebookService.transformEditsOutputs(textModel, cellEdits);
return textModel.applyEdits(modelVersionId, cellEdits, true, undefined, () => undefined);
return textModel.applyEdits(modelVersionId, cellEdits, true, undefined, () => undefined, undefined);
}
private _isDeltaEmpty(delta: INotebookDocumentsAndEditorsDelta) {
......@@ -475,7 +475,7 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
this._notebookService.transformEditsOutputs(mainthreadTextModel, edits);
await new Promise(resolve => {
DOM.scheduleAtNextAnimationFrame(() => {
const ret = mainthreadTextModel!.applyEdits(mainthreadTextModel!.versionId, edits, true, undefined, () => undefined);
const ret = mainthreadTextModel!.applyEdits(mainthreadTextModel!.versionId, edits, true, undefined, () => undefined, undefined);
resolve(ret);
});
});
......@@ -611,7 +611,7 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
index: textModel.cells.indexOf(cell),
splices
}
], true, undefined, () => undefined);
], true, undefined, () => undefined, undefined);
}
async $postMessage(editorId: string, forRendererId: string | undefined, value: any): Promise<boolean> {
......@@ -646,7 +646,7 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
{
editType: CellEditType.Unknown
}
], true, undefined, () => undefined);
], true, undefined, () => undefined, undefined);
}
}
......
......@@ -29,7 +29,7 @@ export class ResourceNotebookCellEdit extends ResourceEdit {
export class BulkCellEdits {
constructor(
undoRedoGroup: UndoRedoGroup,
private _undoRedoGroup: UndoRedoGroup,
private readonly _progress: IProgress<void>,
private readonly _edits: ResourceNotebookCellEdit[],
@INotebookService private readonly _notebookService: INotebookService,
......@@ -53,7 +53,7 @@ export class BulkCellEdits {
// apply edits
const edits = group.map(entry => entry.cellEdit);
this._notebookService.transformEditsOutputs(ref.object.notebook, edits);
ref.object.notebook.applyEdits(ref.object.notebook.versionId, edits, true, undefined, () => undefined);
ref.object.notebook.applyEdits(ref.object.notebook.versionId, edits, true, undefined, () => undefined, this._undoRedoGroup);
ref.dispose();
this._progress.report(undefined);
......
......@@ -622,7 +622,7 @@ export async function changeCellToKind(kind: CellKind, context: INotebookCellAct
metadata: cell.metadata,
}]
}
], true, undefined, () => undefined, true);
], true, undefined, () => undefined, undefined, true);
const newCell = notebookEditor.viewModel.viewCells[idx];
if (!newCell) {
......@@ -1399,7 +1399,7 @@ registerAction2(class extends NotebookCellAction {
return;
}
editor.viewModel.notebookDocument.applyEdits(editor.viewModel.notebookDocument.versionId, [{ editType: CellEditType.Output, index, outputs: [] }], true, undefined, () => undefined);
editor.viewModel.notebookDocument.applyEdits(editor.viewModel.notebookDocument.versionId, [{ editType: CellEditType.Output, index, outputs: [] }], true, undefined, () => undefined, undefined);
if (context.cell.metadata && context.cell.metadata?.runState !== NotebookCellRunState.Running) {
context.notebookEditor.viewModel!.notebookDocument.applyEdits(context.notebookEditor.viewModel!.notebookDocument.versionId, [{
......@@ -1411,7 +1411,7 @@ registerAction2(class extends NotebookCellAction {
statusMessage: undefined,
executionOrder: undefined
}
}], true, undefined, () => undefined);
}], true, undefined, () => undefined, undefined);
}
}
});
......@@ -1494,7 +1494,7 @@ export class ChangeCellLanguageAction extends NotebookCellAction {
context.notebookEditor.viewModel!.notebookDocument.applyEdits(
context.notebookEditor.viewModel!.notebookDocument.versionId,
[{ editType: CellEditType.CellLanguage, index, language: selection.languageId }],
true, undefined, () => undefined
true, undefined, () => undefined, undefined
);
}
}
......@@ -1545,7 +1545,7 @@ registerAction2(class extends NotebookAction {
editor.viewModel.notebookDocument.applyEdits(editor.viewModel.notebookDocument.versionId,
editor.viewModel.notebookDocument.cells.map((cell, index) => ({
editType: CellEditType.Output, index, outputs: []
})), true, undefined, () => undefined);
})), true, undefined, () => undefined, undefined);
const clearExecutionMetadataEdits = editor.viewModel.notebookDocument.cells.map((cell, index) => {
if (cell.metadata && cell.metadata?.runState !== NotebookCellRunState.Running) {
......@@ -1564,7 +1564,7 @@ registerAction2(class extends NotebookAction {
}
}).filter(edit => !!edit) as ICellEditOperation[];
if (clearExecutionMetadataEdits.length) {
context.notebookEditor.viewModel!.notebookDocument.applyEdits(context.notebookEditor.viewModel!.notebookDocument.versionId, clearExecutionMetadataEdits, true, undefined, () => undefined);
context.notebookEditor.viewModel!.notebookDocument.applyEdits(context.notebookEditor.viewModel!.notebookDocument.versionId, clearExecutionMetadataEdits, true, undefined, () => undefined, undefined);
}
}
});
......@@ -1699,7 +1699,7 @@ abstract class ChangeNotebookCellMetadataAction extends NotebookCellAction {
return;
}
textModel.applyEdits(textModel.versionId, [{ editType: CellEditType.Metadata, index, metadata: { ...context.cell.metadata, ...this.getMetadataDelta() } }], true, undefined, () => undefined);
textModel.applyEdits(textModel.versionId, [{ editType: CellEditType.Metadata, index, metadata: { ...context.cell.metadata, ...this.getMetadataDelta() } }], true, undefined, () => undefined, undefined);
}
abstract getMetadataDelta(): NotebookCellMetadata;
......
......@@ -493,7 +493,8 @@ abstract class AbstractCellRenderer extends Disposable {
[{ editType: CellEditType.CellLanguage, index, language: newLangauge }],
true,
undefined,
() => undefined
() => undefined,
undefined
);
}
......@@ -505,7 +506,7 @@ abstract class AbstractCellRenderer extends Disposable {
this.notebookEditor.textModel!.applyEdits(this.notebookEditor.textModel!.versionId, [
{ editType: CellEditType.Metadata, index, metadata: result }
], true, undefined, () => undefined);
], true, undefined, () => undefined, undefined);
} catch {
}
}
......
......@@ -342,11 +342,11 @@ abstract class AbstractCellRenderer {
if (templateData.currentRenderedCell.metadata?.inputCollapsed) {
textModel.applyEdits(textModel.versionId, [
{ editType: CellEditType.Metadata, index, metadata: { ...templateData.currentRenderedCell.metadata, inputCollapsed: false } }
], true, undefined, () => undefined);
], true, undefined, () => undefined, undefined);
} else if (templateData.currentRenderedCell.metadata?.outputCollapsed) {
textModel.applyEdits(textModel.versionId, [
{ editType: CellEditType.Metadata, index, metadata: { ...templateData.currentRenderedCell.metadata, outputCollapsed: false } }
], true, undefined, () => undefined);
], true, undefined, () => undefined, undefined);
}
}));
}
......
......@@ -256,7 +256,7 @@ export class CellDragAndDropController extends Disposable {
}
private copyCells(draggedCells: ICellViewModel[], ontoCell: ICellViewModel, direction: 'above' | 'below') {
this.notebookEditor.textModel!.pushStackElement('Copy Cells', undefined);
this.notebookEditor.textModel!.pushStackElement('Copy Cells', undefined, undefined);
let firstNewCell: ICellViewModel | undefined = undefined;
let firstNewCellState: CellEditState = CellEditState.Preview;
for (let i = 0; i < draggedCells.length; i++) {
......@@ -273,6 +273,6 @@ export class CellDragAndDropController extends Disposable {
this.notebookEditor.focusNotebookCell(firstNewCell, firstNewCellState === CellEditState.Editing ? 'editor' : 'container');
}
this.notebookEditor.textModel!.pushStackElement('Copy Cells', undefined);
this.notebookEditor.textModel!.pushStackElement('Copy Cells', undefined, undefined);
}
}
......@@ -74,63 +74,3 @@ export class JoinCellEdit implements IResourceUndoRedoElement {
this.cell.focusMode = CellFocusMode.Editor;
}
}
export class SplitCellEdit implements IResourceUndoRedoElement {
type: UndoRedoElementType.Resource = UndoRedoElementType.Resource;
label: string = 'Join Cell';
constructor(
public resource: URI,
private index: number,
private cell: BaseCellViewModel,
private selections: Selection[],
private cellContents: string[],
private language: string,
private cellKind: CellKind,
private editingDelegate: IViewCellEditingDelegate
) {
}
async undo(): Promise<void> {
if (!this.editingDelegate.deleteCell) {
throw new Error('Notebook Delete Cell not implemented for Undo/Redo');
}
await this.cell.resolveTextModel();
this.cell.textModel!.applyEdits([
{
range: this.cell.textModel!.getFullModelRange(),
text: this.cellContents.join('')
}
]);
this.cell.setSelections(this.selections);
for (let j = 1; j < this.cellContents.length; j++) {
this.editingDelegate.deleteCell(this.index + 1, j === this.cellContents.length - 1 ? [this.cell.handle] : undefined);
}
this.cell.focusMode = CellFocusMode.Editor;
}
async redo(): Promise<void> {
if (!this.editingDelegate.createCell) {
throw new Error('Notebook Insert Cell not implemented for Undo/Redo');
}
await this.cell.resolveTextModel();
this.cell.textModel!.applyEdits([
{ range: this.cell.textModel!.getFullModelRange(), text: this.cellContents[0] }
], false);
let insertIndex = this.index + 1;
let lastCell;
for (let j = 1; j < this.cellContents.length; j++, insertIndex++) {
lastCell = this.editingDelegate.createCell(insertIndex, this.cellContents[j], this.language, this.cellKind, {}, []);
}
if (lastCell) {
lastCell.focusMode = CellFocusMode.Editor;
}
}
}
......@@ -29,10 +29,10 @@ import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/no
import { MarkdownRenderer } from 'vs/workbench/contrib/notebook/browser/view/renderers/mdRenderer';
import { dirname } from 'vs/base/common/resources';
import { IPosition, Position } from 'vs/editor/common/core/position';
import { SplitCellEdit, JoinCellEdit } from 'vs/workbench/contrib/notebook/browser/viewModel/cellEdit';
import { BaseCellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/baseCellViewModel';
import { JoinCellEdit } from 'vs/workbench/contrib/notebook/browser/viewModel/cellEdit';
import { PieceTreeTextBuffer } from 'vs/editor/common/model/pieceTreeTextBuffer/pieceTreeTextBuffer';
import { MultiModelEditStackElement, SingleModelEditStackElement } from 'vs/editor/common/model/editStack';
import { ResourceNotebookCellEdit } from 'vs/workbench/contrib/bulkEdit/browser/bulkCellEdits';
export interface INotebookEditorViewState {
editingCells: { [key: number]: boolean };
......@@ -664,7 +664,7 @@ export class NotebookViewModel extends Disposable implements EditorFoldingStateD
}
]
}
], synchronous, beforeSelections, () => undefined);
], synchronous, beforeSelections, () => undefined, undefined);
return this._viewCells[index];
}
......@@ -697,6 +697,7 @@ export class NotebookViewModel extends Disposable implements EditorFoldingStateD
synchronous,
this.selectionHandles,
() => endSelections,
undefined,
pushUndoStop
);
}
......@@ -722,7 +723,7 @@ export class NotebookViewModel extends Disposable implements EditorFoldingStateD
length,
newIdx
}
], synchronous, undefined, () => [viewCell.handle]);
], synchronous, undefined, () => [viewCell.handle], undefined);
return true;
}
......@@ -806,47 +807,30 @@ export class NotebookViewModel extends Disposable implements EditorFoldingStateD
const newLinesContents = this._computeCellLinesContents(cell, splitPoints);
if (newLinesContents) {
const editorSelections = cell.getSelections();
const language = cell.language;
const kind = cell.cellKind;
this._notebook.applyEdits(this._notebook.versionId, [
{
editType: CellEditType.CellContent,
index,
range: undefined,
text: newLinesContents[0]
},
{
editType: CellEditType.Replace,
index: index + 1,
count: 0,
cells: newLinesContents.slice(1).map(line => ({
cellKind: kind,
language,
source: line,
outputs: [],
metadata: {}
}))
}
], true, undefined, () => this.selectionHandles, false);
this._undoService.pushElement(new SplitCellEdit(
this.uri,
index,
cell,
editorSelections,
newLinesContents,
language,
kind,
{
createCell: (index: number, source: string, language: string, type: CellKind, metadata: NotebookCellMetadata | undefined, outputs: IProcessedOutput[]) => {
return this.createCell(index, source, language, type, metadata, outputs, true, false) as BaseCellViewModel;
},
deleteCell: (index: number) => {
this.deleteCell(index, true, false);
}
}
));
const textModel = await cell.resolveTextModel();
await this._bulkEditService.apply(
[
new ResourceTextEdit(cell.uri, { range: textModel.getFullModelRange(), text: newLinesContents[0] }),
new ResourceNotebookCellEdit(this._notebook.uri,
{
editType: CellEditType.Replace,
index: index + 1,
count: 0,
cells: newLinesContents.slice(1).map(line => ({
cellKind: kind,
language,
source: line,
outputs: [],
metadata: {}
}))
}
)
],
{ quotableLabel: 'Split Notebook Cell' }
);
}
}
......
......@@ -10,11 +10,10 @@ import { URI } from 'vs/base/common/uri';
import { NotebookCellTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookCellTextModel';
import { INotebookTextModel, NotebookCellOutputsSplice, NotebookDocumentMetadata, NotebookCellMetadata, ICellEditOperation, CellEditType, CellUri, notebookDocumentMetadataDefaults, diff, NotebookCellsChangeType, ICellDto2, TransientOptions, NotebookTextModelChangedEvent, NotebookRawContentEvent, IProcessedOutput, CellOutputKind } 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 { IUndoRedoService, UndoRedoElementType, IUndoRedoElement, IResourceUndoRedoElement, UndoRedoGroup, IWorkspaceUndoRedoElement } from 'vs/platform/undoRedo/common/undoRedo';
import { MoveCellEdit, SpliceCellsEdit, CellMetadataEdit } from 'vs/workbench/contrib/notebook/common/model/cellEdit';
import { ITextModelService } from 'vs/editor/common/services/resolverService';
import { IModeService } from 'vs/editor/common/services/modeService';
import { IRange } from 'vs/editor/common/core/range';
import { ISequence, LcsDiff } from 'vs/base/common/diff/diff';
import { hash } from 'vs/base/common/hash';
......@@ -57,21 +56,25 @@ export class NotebookTextModelSnapshot implements ITextSnapshot {
}
class StackOperation implements IResourceUndoRedoElement {
type: UndoRedoElementType.Resource;
class StackOperation implements IWorkspaceUndoRedoElement {
type: UndoRedoElementType.Workspace;
private _operations: IUndoRedoElement[] = [];
private _beginSelectionState: number[] | undefined = undefined;
private _resultSelectionState: number[] | undefined = undefined;
constructor(readonly resource: URI, readonly label: string, private _delayedEmitter: DelayedEmitter, selectionState: number[] | undefined) {
this.type = UndoRedoElementType.Resource;
constructor(readonly resource: URI, readonly label: string, readonly undoRedoGroup: UndoRedoGroup | undefined, private _delayedEmitter: DelayedEmitter, selectionState: number[] | undefined) {
this.type = UndoRedoElementType.Workspace;
this._beginSelectionState = selectionState;
}
get resources(): readonly URI[] {
return [this.resource];
}
pushEndSelectionState(selectionState: number[] | undefined) {
this._resultSelectionState = selectionState;
}
pushEditOperation(element: IUndoRedoElement, beginSelectionState: number[] | undefined, resultSelectionState: number[] | undefined) {
if (this._operations.length === 0) {
this._beginSelectionState = this._beginSelectionState || beginSelectionState;
......@@ -103,15 +106,15 @@ export class NotebookOperationManager {
}
pushStackElement(label: string, selectionState: number[] | undefined) {
pushStackElement(label: string, selectionState: number[] | undefined, undoRedoGroup: UndoRedoGroup | undefined) {
if (this._pendingStackOperation) {
this._pendingStackOperation.pushEndSelectionState(selectionState);
this._undoService.pushElement(this._pendingStackOperation);
this._undoService.pushElement(this._pendingStackOperation, this._pendingStackOperation.undoRedoGroup);
this._pendingStackOperation = null;
return;
}
this._pendingStackOperation = new StackOperation(this._resource, label, this._delayedEmitter, selectionState);
this._pendingStackOperation = new StackOperation(this._resource, label, undoRedoGroup, this._delayedEmitter, selectionState);
}
pushEditOperation(element: IUndoRedoElement, beginSelectionState: number[] | undefined, resultSelectionState: number[] | undefined) {
......@@ -289,17 +292,17 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
super.dispose();
}
pushStackElement(label: string, selectionState: number[] | undefined) {
this._operationManager.pushStackElement(label, selectionState);
pushStackElement(label: string, selectionState: number[] | undefined, undoRedoGroup: UndoRedoGroup | undefined) {
this._operationManager.pushStackElement(label, selectionState, undoRedoGroup);
}
applyEdits(modelVersionId: number, rawEdits: ICellEditOperation[], synchronous: boolean, beginSelectionState: number[] | undefined, endSelectionsComputer: () => number[] | undefined, computeUndoRedo: boolean = true): boolean {
applyEdits(modelVersionId: number, rawEdits: ICellEditOperation[], synchronous: boolean, beginSelectionState: number[] | undefined, endSelectionsComputer: () => number[] | undefined, undoRedoGroup: UndoRedoGroup | undefined, computeUndoRedo: boolean = true): boolean {
if (modelVersionId !== this._versionId) {
return false;
}
this._eventEmitter.beginDeferredEmit();
this.pushStackElement('edit', beginSelectionState);
this.pushStackElement('edit', beginSelectionState, undoRedoGroup);
const edits = rawEdits.map((edit, index) => {
return {
......@@ -355,10 +358,6 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
case CellEditType.Move:
this._moveCellToIdx(edit.index, edit.length, edit.newIdx, synchronous, computeUndoRedo, undefined, undefined);
break;
case CellEditType.CellContent:
// TODO@rebornix, _replaceCellContent is async and does not push undo element
this._replaceCellContent(this._cells[edit.index], edit.range, edit.text);
break;
case CellEditType.Unknown:
this._handleUnknownChange();
break;
......@@ -366,7 +365,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
}
const endSelections = endSelectionsComputer();
this.pushStackElement('edit', endSelections);
this.pushStackElement('edit', endSelections, undefined);
this._eventEmitter.endDeferredEmit(endSelections);
return true;
}
......@@ -691,17 +690,6 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
return true;
}
async _replaceCellContent(cell: NotebookCellTextModel, range: IRange | undefined, text: string) {
const ref = await cell.resolveTextModelRef();
const textModel = ref.object.textEditorModel;
textModel.applyEdits([
{ range: range || textModel.getFullModelRange(), text: text }
], false);
ref.dispose();
}
private _assertIndex(index: number) {
if (index < 0 || index >= this._cells.length) {
throw new Error(`model index out of range ${index}`);
......
......@@ -23,7 +23,6 @@ import { IRevertOptions } from 'vs/workbench/common/editor';
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
import { IDisposable } from 'vs/base/common/lifecycle';
import { IFileStatWithMetadata } from 'vs/platform/files/common/files';
import { IRange } from 'vs/editor/common/core/range';
import { ThemeColor } from 'vs/platform/theme/common/themeService';
export enum CellKind {
......@@ -482,18 +481,11 @@ export interface ICellMoveEdit {
newIdx: number;
}
export interface ICellContentEdit {
editType: CellEditType.CellContent;
index: number;
range: IRange | undefined;
text: string;
}
export interface IDocumentUnknownEdit {
editType: CellEditType.Unknown;
}
export type ICellEditOperation = ICellReplaceEdit | ICellOutputEdit | ICellMetadataEdit | ICellLanguageEdit | IDocumentMetadataEdit | ICellOutputsSpliceEdit | ICellMoveEdit | ICellContentEdit | IDocumentUnknownEdit;
export type ICellEditOperation = ICellReplaceEdit | ICellOutputEdit | ICellMetadataEdit | ICellLanguageEdit | IDocumentMetadataEdit | ICellOutputsSpliceEdit | ICellMoveEdit | IDocumentUnknownEdit;
export interface INotebookEditData {
documentVersionId: number;
......
......@@ -32,7 +32,7 @@ suite('NotebookTextModel', () => {
textModel.applyEdits(textModel.versionId, [
{ editType: CellEditType.Replace, index: 1, count: 0, cells: [new TestCell(viewModel.viewType, 5, 'var e = 5;', 'javascript', CellKind.Code, [], textModelService)] },
{ editType: CellEditType.Replace, index: 3, count: 0, cells: [new TestCell(viewModel.viewType, 6, 'var f = 6;', 'javascript', CellKind.Code, [], textModelService)] },
], true, undefined, () => undefined);
], true, undefined, () => undefined, undefined);
assert.equal(textModel.cells.length, 6);
......@@ -57,7 +57,7 @@ suite('NotebookTextModel', () => {
textModel.applyEdits(textModel.versionId, [
{ editType: CellEditType.Replace, index: 1, count: 0, cells: [new TestCell(viewModel.viewType, 5, 'var e = 5;', 'javascript', CellKind.Code, [], textModelService)] },
{ editType: CellEditType.Replace, index: 1, count: 0, cells: [new TestCell(viewModel.viewType, 6, 'var f = 6;', 'javascript', CellKind.Code, [], textModelService)] },
], true, undefined, () => undefined);
], true, undefined, () => undefined, undefined);
assert.equal(textModel.cells.length, 6);
......@@ -82,7 +82,7 @@ suite('NotebookTextModel', () => {
textModel.applyEdits(textModel.versionId, [
{ editType: CellEditType.Replace, index: 1, count: 1, cells: [] },
{ editType: CellEditType.Replace, index: 3, count: 1, cells: [] },
], true, undefined, () => undefined);
], true, undefined, () => undefined, undefined);
assert.equal(textModel.cells[0].getValue(), 'var a = 1;');
assert.equal(textModel.cells[1].getValue(), 'var c = 3;');
......@@ -105,7 +105,7 @@ suite('NotebookTextModel', () => {
textModel.applyEdits(textModel.versionId, [
{ editType: CellEditType.Replace, index: 1, count: 1, cells: [] },
{ editType: CellEditType.Replace, index: 3, count: 0, cells: [new TestCell(viewModel.viewType, 5, 'var e = 5;', 'javascript', CellKind.Code, [], textModelService)] },
], true, undefined, () => undefined);
], true, undefined, () => undefined, undefined);
assert.equal(textModel.cells.length, 4);
......@@ -130,7 +130,7 @@ suite('NotebookTextModel', () => {
textModel.applyEdits(textModel.versionId, [
{ editType: CellEditType.Replace, index: 1, count: 1, cells: [] },
{ editType: CellEditType.Replace, index: 1, count: 0, cells: [new TestCell(viewModel.viewType, 5, 'var e = 5;', 'javascript', CellKind.Code, [], textModelService)] },
], true, undefined, () => undefined);
], true, undefined, () => undefined, undefined);
assert.equal(textModel.cells.length, 4);
assert.equal(textModel.cells[0].getValue(), 'var a = 1;');
......@@ -154,7 +154,7 @@ suite('NotebookTextModel', () => {
(editor, viewModel, textModel) => {
textModel.applyEdits(textModel.versionId, [
{ editType: CellEditType.Replace, index: 1, count: 1, cells: [new TestCell(viewModel.viewType, 5, 'var e = 5;', 'javascript', CellKind.Code, [], textModelService)] },
], true, undefined, () => undefined);
], true, undefined, () => undefined, undefined);
assert.equal(textModel.cells.length, 4);
assert.equal(textModel.cells[0].getValue(), 'var a = 1;');
......@@ -180,7 +180,7 @@ suite('NotebookTextModel', () => {
index: Number.MAX_VALUE,
editType: CellEditType.Output,
outputs: []
}], true, undefined, () => undefined);
}], true, undefined, () => undefined, undefined);
});
// invalid index 2
......@@ -189,7 +189,7 @@ suite('NotebookTextModel', () => {
index: -1,
editType: CellEditType.Output,
outputs: []
}], true, undefined, () => undefined);
}], true, undefined, () => undefined, undefined);
});
textModel.applyEdits(textModel.versionId, [{
......@@ -200,7 +200,7 @@ suite('NotebookTextModel', () => {
outputId: 'someId',
data: { 'text/markdown': '_Hello_' }
}]
}], true, undefined, () => undefined);
}], true, undefined, () => undefined, undefined);
assert.equal(textModel.cells.length, 1);
assert.equal(textModel.cells[0].outputs.length, 1);
......@@ -225,7 +225,7 @@ suite('NotebookTextModel', () => {
index: Number.MAX_VALUE,
editType: CellEditType.Metadata,
metadata: { editable: false }
}], true, undefined, () => undefined);
}], true, undefined, () => undefined, undefined);
});
// invalid index 2
......@@ -234,14 +234,14 @@ suite('NotebookTextModel', () => {
index: -1,
editType: CellEditType.Metadata,
metadata: { editable: false }
}], true, undefined, () => undefined);
}], true, undefined, () => undefined, undefined);
});
textModel.applyEdits(textModel.versionId, [{
index: 0,
editType: CellEditType.Metadata,
metadata: { editable: false },
}], true, undefined, () => undefined);
}], true, undefined, () => undefined, undefined);
assert.equal(textModel.cells.length, 1);
assert.equal(textModel.cells[0].metadata?.editable, false);
......@@ -270,7 +270,7 @@ suite('NotebookTextModel', () => {
textModel.applyEdits(textModel.versionId, [
{ editType: CellEditType.Replace, index: 1, count: 1, cells: [] },
{ editType: CellEditType.Replace, index: 1, count: 0, cells: [new TestCell(viewModel.viewType, 5, 'var e = 5;', 'javascript', CellKind.Code, [], textModelService)] },
], true, undefined, () => [0]);
], true, undefined, () => [0], undefined);
assert.equal(textModel.cells.length, 4);
assert.equal(textModel.cells[0].getValue(), 'var a = 1;');
......@@ -311,7 +311,7 @@ suite('NotebookTextModel', () => {
editType: CellEditType.Metadata,
metadata: { editable: false },
}
], true, undefined, () => [0]);
], true, undefined, () => [0], undefined);
assert.notEqual(changeEvent, undefined);
assert.equal(changeEvent!.rawEvents.length, 2);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册