@@ -15,6 +15,7 @@ import { URI } from 'vs/base/common/uri';
1515import { generateUuid } from 'vs/base/common/uuid' ;
1616import { FileSystemProviderErrorCode , markAsFileSystemProviderError } from 'vs/platform/files/common/files' ;
1717import { RemoteAuthorityResolverErrorCode } from 'vs/platform/remote/common/remoteAuthorityResolver' ;
18+ import { addIdToOutput , CellEditType , ICellEditOperation } from 'vs/workbench/contrib/notebook/common/notebookCommon' ;
1819import type * as vscode from 'vscode' ;
1920
2021function es5ClassCompat ( target : Function ) : any {
@@ -578,7 +579,8 @@ export interface IFileOperationOptions {
578579
579580export const enum FileEditType {
580581 File = 1 ,
581- Text = 2
582+ Text = 2 ,
583+ Cell = 3
582584}
583585
584586export interface IFileOperation {
@@ -596,13 +598,20 @@ export interface IFileTextEdit {
596598 metadata ?: vscode . WorkspaceEditEntryMetadata ;
597599}
598600
601+ export interface IFileCellEdit {
602+ _type : FileEditType . Cell ;
603+ uri : URI ;
604+ edit : ICellEditOperation ;
605+ metadata ?: vscode . WorkspaceEditEntryMetadata ;
606+ }
607+
599608@es5ClassCompat
600609export class WorkspaceEdit implements vscode . WorkspaceEdit {
601610
602- private readonly _edits = new Array < IFileOperation | IFileTextEdit > ( ) ;
611+ private readonly _edits = new Array < IFileOperation | IFileTextEdit | IFileCellEdit > ( ) ;
603612
604613
605- allEntries ( ) : ReadonlyArray < IFileTextEdit | IFileOperation > {
614+ _allEntries ( ) : ReadonlyArray < IFileTextEdit | IFileOperation | IFileCellEdit > {
606615 return this . _edits ;
607616 }
608617
@@ -620,6 +629,21 @@ export class WorkspaceEdit implements vscode.WorkspaceEdit {
620629 this . _edits . push ( { _type : FileEditType . File , from : uri , to : undefined , options, metadata } ) ;
621630 }
622631
632+ // --- cell
633+
634+ replaceCells ( uri : URI , start : number , end : number , cells : vscode . NotebookCellData [ ] , metadata ?: vscode . WorkspaceEditEntryMetadata ) : void {
635+ this . _edits . push ( { _type : FileEditType . Cell , metadata, uri, edit : { editType : CellEditType . Delete , index : start , count : end - start } } ) ;
636+ this . _edits . push ( { _type : FileEditType . Cell , metadata, uri, edit : { editType : CellEditType . Insert , index : start , cells : cells . map ( cell => ( { ...cell , outputs : cell . outputs . map ( output => addIdToOutput ( output ) ) } ) ) } } ) ;
637+ }
638+
639+ replaceCellOutput ( uri : URI , index : number , outputs : vscode . CellOutput [ ] , metadata ?: vscode . WorkspaceEditEntryMetadata ) : void {
640+ this . _edits . push ( { _type : FileEditType . Cell , metadata, uri, edit : { editType : CellEditType . Output , index, outputs : outputs . map ( output => addIdToOutput ( output ) ) } } ) ;
641+ }
642+
643+ replaceCellMetadata ( uri : URI , index : number , cellMetadata : vscode . NotebookCellMetadata , metadata ?: vscode . WorkspaceEditEntryMetadata ) : void {
644+ this . _edits . push ( { _type : FileEditType . Cell , metadata, uri, edit : { editType : CellEditType . Metadata , index, metadata : cellMetadata } } ) ;
645+ }
646+
623647 // --- text
624648
625649 replace ( uri : URI , range : Range , newText : string , metadata ?: vscode . WorkspaceEditEntryMetadata ) : void {
0 commit comments