提交 ac4de7bb 编写于 作者: J Johannes Rieken

add NotebookEditorCellEdit#replaceOutputs, https://github.com/microsoft/vscode/issues/105283

上级 bc9f2577
......@@ -1357,6 +1357,8 @@ declare module 'vscode' {
replaceCells(from: number, to: number, cells: NotebookCellData[]): void;
replaceOutputs(index: number, outputs: CellOutput[]): void;
/** @deprecated */
insert(index: number, content: string | string[], language: string, type: CellKind, outputs: CellOutput[], metadata: NotebookCellMetadata | undefined): void;
/** @deprecated */
......
......@@ -560,7 +560,7 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
if (textModel) {
this._notebookService.transformSpliceOutputs(textModel, splices);
textModel.$spliceNotebookCellOutputs(cellHandle, splices);
textModel.spliceNotebookCellOutputs(cellHandle, splices);
}
}
......
......@@ -511,6 +511,15 @@ export class NotebookEditorCellEditBuilder implements vscode.NotebookEditorCellE
}
}
replaceOutputs(index: number, outputs: vscode.CellOutput[]): void {
this._throwIfFinalized();
this._collectedEdits.push({
editType: CellEditType.Output,
index,
outputs: outputs.map(output => addIdToOutput(output))
});
}
replaceCells(from: number, to: number, cells: vscode.NotebookCellData[]): void {
this._throwIfFinalized();
......
......@@ -733,6 +733,16 @@ export class NotebookService extends Disposable implements INotebookService, ICu
}
});
});
} else if (edit.editType === CellEditType.Output) {
edit.outputs.map((output) => {
if (output.outputKind === CellOutputKind.Rich) {
const ret = this._transformMimeTypes(output, output.outputId, textModel.metadata.displayOrder as string[] || []);
const orderedMimeTypes = ret.orderedMimeTypes!;
const pickedMimeTypeIndex = ret.pickedMimeTypeIndex!;
output.pickedMimeTypeIndex = pickedMimeTypeIndex;
output.orderedMimeTypes = orderedMimeTypes;
}
});
}
});
}
......
......@@ -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, ICellInsertEdit, NotebookCellsChangedEvent, CellKind, IProcessedOutput, notebookDocumentMetadataDefaults, diff, ICellDeleteEdit, NotebookCellsChangeType, ICellDto2, IMainCellDto } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { INotebookTextModel, NotebookCellOutputsSplice, NotebookCellTextModelSplice, NotebookDocumentMetadata, NotebookCellMetadata, ICellEditOperation, CellEditType, CellUri, ICellInsertEdit, NotebookCellsChangedEvent, CellKind, IProcessedOutput, notebookDocumentMetadataDefaults, diff, ICellDeleteEdit, NotebookCellsChangeType, ICellDto2, IMainCellDto, ICellOutputEdit } 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 } from 'vs/workbench/contrib/notebook/common/model/cellEdit';
......@@ -279,6 +279,11 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
case CellEditType.Delete:
this.removeCell(operations[i].index, operations[i].end - operations[i].start, false);
break;
case CellEditType.Output:
//TODO@joh,@rebornix no event, no undo stop (?)
const cell = this.cells[operations[i].index];
this.spliceNotebookCellOutputs(cell.handle, [[0, cell.outputs.length, (<ICellOutputEdit>operations[i]).outputs]]);
break;
}
}
......@@ -493,7 +498,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
}
// TODO@rebornix should this trigger content change event?
$spliceNotebookCellOutputs(cellHandle: number, splices: NotebookCellOutputsSplice[]): void {
spliceNotebookCellOutputs(cellHandle: number, splices: NotebookCellOutputsSplice[]): void {
const cell = this._mapping.get(cellHandle);
cell?.spliceNotebookCellOutputs(splices);
}
......
......@@ -398,9 +398,11 @@ export interface NotebookCellsChangeMetadataEvent {
}
export type NotebookCellsChangedEvent = NotebookCellsInitializeEvent | NotebookCellsModelChangedEvent | NotebookCellsModelMoveEvent | NotebookCellClearOutputEvent | NotebookCellsClearOutputEvent | NotebookCellsChangeLanguageEvent | NotebookCellsChangeMetadataEvent;
export enum CellEditType {
export const enum CellEditType {
Insert = 1,
Delete = 2
Delete = 2,
Output = 3,
}
export interface ICellDto2 {
......@@ -423,7 +425,13 @@ export interface ICellDeleteEdit {
count: number;
}
export type ICellEditOperation = ICellInsertEdit | ICellDeleteEdit;
export interface ICellOutputEdit {
editType: CellEditType.Output;
index: number,
outputs: IProcessedOutput[]
}
export type ICellEditOperation = ICellInsertEdit | ICellDeleteEdit | ICellOutputEdit;
export interface INotebookEditData {
documentVersionId: number;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册