提交 03fdd53f 编写于 作者: R rebornix

append/replace output items

上级 008e5c73
......@@ -1502,8 +1502,8 @@ declare module 'vscode' {
// TODO@api
// https://jupyter-protocol.readthedocs.io/en/latest/messaging.html#update-display-data
// replaceNotebookCellOutput(uri: Uri, index: number, outputId:string, outputs: NotebookCellOutput[], metadata?: WorkspaceEditEntryMetadata): void;
// appendNotebookCellOutput(uri: Uri, index: number, outputId:string, outputs: NotebookCellOutput[], metadata?: WorkspaceEditEntryMetadata): void;
replaceNotebookCellOutputItems(uri: Uri, index: number, outputId: string, items: NotebookCellOutputItem[], metadata?: WorkspaceEditEntryMetadata): void;
appendNotebookCellOutputItems(uri: Uri, index: number, outputId: string, items: NotebookCellOutputItem[], metadata?: WorkspaceEditEntryMetadata): void;
}
export interface NotebookEditorEdit {
......
......@@ -587,6 +587,18 @@ export namespace WorkspaceEdit {
cells: entry.cells.map(NotebookCellData.from)
}
});
} else if (entry._type === types.FileEditType.CellOutputItem) {
result.edits.push({
_type: extHostProtocol.WorkspaceEditType.Cell,
metadata: entry.metadata,
resource: entry.uri,
edit: {
editType: CellEditType.OutputItems,
index: entry.index,
outputId: entry.outputId,
data: entry.newOutputItems ? entry.newOutputItems.reduce((a, x) => ({ ...a, [x.mime]: x.value }), {}) : []
}
});
}
}
}
......
......@@ -588,6 +588,7 @@ export const enum FileEditType {
Cell = 3,
CellOutput = 4,
CellReplace = 5,
CellOutputItem = 6
}
export interface IFileOperation {
......@@ -632,8 +633,18 @@ export interface ICellOutputEdit {
metadata?: vscode.WorkspaceEditEntryMetadata;
}
export interface ICellOutputItemsEdit {
_type: FileEditType.CellOutputItem;
uri: URI;
index: number;
outputId: string;
append: boolean;
newOutputItems?: NotebookCellOutputItem[];
metadata?: vscode.WorkspaceEditEntryMetadata;
}
type WorkspaceEditEntry = IFileOperation | IFileTextEdit | IFileCellEdit | ICellEdit | ICellOutputEdit;
type WorkspaceEditEntry = IFileOperation | IFileTextEdit | IFileCellEdit | ICellEdit | ICellOutputEdit | ICellOutputItemsEdit;
@es5ClassCompat
export class WorkspaceEdit implements vscode.WorkspaceEdit {
......@@ -679,6 +690,18 @@ export class WorkspaceEdit implements vscode.WorkspaceEdit {
this._editNotebookCellOutput(uri, index, true, outputs, metadata);
}
replaceNotebookCellOutputItems(uri: URI, index: number, outputId: string, items: NotebookCellOutputItem[], metadata?: vscode.WorkspaceEditEntryMetadata): void {
this._editNotebookCellOutputItems(uri, index, outputId, false, items, metadata);
}
appendNotebookCellOutputItems(uri: URI, index: number, outputId: string, items: NotebookCellOutputItem[], metadata?: vscode.WorkspaceEditEntryMetadata): void {
this._editNotebookCellOutputItems(uri, index, outputId, true, items, metadata);
}
private _editNotebookCellOutputItems(uri: URI, index: number, id: string, append: boolean, items: vscode.NotebookCellOutputItem[], metadata: vscode.WorkspaceEditEntryMetadata | undefined): void {
this._edits.push({ _type: FileEditType.CellOutputItem, metadata, uri, index, outputId: id, append, newOutputItems: items });
}
private _editNotebookCellOutput(uri: URI, index: number, append: boolean, outputs: (vscode.NotebookCellOutput | vscode.CellOutput)[], metadata: vscode.WorkspaceEditEntryMetadata | undefined): void {
let newOutputs: NotebookCellOutput[];
const [first] = outputs;
......
......@@ -345,6 +345,17 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
this._spliceNotebookCellOutputs2(cell.handle, edit.outputs, computeUndoRedo);
}
break;
case CellEditType.OutputItems:
{
this._assertIndex(edit.index);
const cell = this._cells[edit.index];
if (edit.append) {
this._appendNotebookCellOutputItems(cell.handle, edit.outputId, edit.data);
} else {
this._replaceNotebookCellOutputItems(cell.handle, edit.outputId, edit.data);
}
}
break;
case CellEditType.OutputsSplice:
{
//TODO@jrieken,@rebornix no event, no undo stop (?)
......@@ -675,6 +686,40 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
}
}
private _appendNotebookCellOutputItems(cellHandle: number, outputId: string, data: { [key: string]: any }) {
const cell = this._mapping.get(cellHandle);
if (!cell) {
return;
}
const outputIndex = cell.outputs.findIndex(output => output.outputId === outputId);
if (outputIndex < 0) {
return;
}
const output = cell.outputs[outputIndex];
output.data = data;
cell.spliceNotebookCellOutputs([[outputIndex, 1, [output]]]);
}
private _replaceNotebookCellOutputItems(cellHandle: number, outputId: string, data: { [key: string]: any }) {
const cell = this._mapping.get(cellHandle);
if (!cell) {
return;
}
const outputIndex = cell.outputs.findIndex(output => output.outputId === outputId);
if (outputIndex < 0) {
return;
}
const output = cell.outputs[outputIndex];
output.data = data;
cell.spliceNotebookCellOutputs([[outputIndex, 1, [output]]]);
}
private _moveCellToIdx(index: number, length: number, newIdx: number, synchronous: boolean, pushedToUndoStack: boolean, beforeSelections: number[] | undefined, endSelections: number[] | undefined): boolean {
if (pushedToUndoStack) {
this._operationManager.pushEditOperation(new MoveCellEdit(this.uri, index, length, newIdx, {
......
......@@ -303,7 +303,8 @@ export const enum CellEditType {
OutputsSplice = 6,
Move = 7,
Unknown = 8,
CellContent = 9
CellContent = 9,
OutputItems = 10
}
export interface ICellDto2 {
......@@ -328,6 +329,14 @@ export interface ICellOutputEdit {
append?: boolean
}
export interface ICellOutputItemEdit {
editType: CellEditType.OutputItems;
index: number;
outputId: string;
data: { [key: string]: unknown; }
append?: boolean;
}
export interface ICellMetadataEdit {
editType: CellEditType.Metadata;
index: number;
......@@ -359,7 +368,7 @@ export interface ICellMoveEdit {
newIdx: number;
}
export type ICellEditOperation = ICellReplaceEdit | ICellOutputEdit | ICellMetadataEdit | ICellLanguageEdit | IDocumentMetadataEdit | ICellOutputsSpliceEdit | ICellMoveEdit;
export type ICellEditOperation = ICellReplaceEdit | ICellOutputEdit | ICellMetadataEdit | ICellLanguageEdit | IDocumentMetadataEdit | ICellOutputsSpliceEdit | ICellMoveEdit | ICellOutputItemEdit;
export interface INotebookEditData {
documentVersionId: number;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册