From c0efffc91f0c4cd10e70f30229f19da96a50f960 Mon Sep 17 00:00:00 2001 From: rebornix Date: Thu, 26 Mar 2020 11:32:35 -0700 Subject: [PATCH] insert and delete index should be on the model before edit. --- src/vs/workbench/api/common/extHostNotebook.ts | 14 +++++++++++--- .../contrib/notebook/common/notebookCommon.ts | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/vs/workbench/api/common/extHostNotebook.ts b/src/vs/workbench/api/common/extHostNotebook.ts index c85638f4011..8416274e5d7 100644 --- a/src/vs/workbench/api/common/extHostNotebook.ts +++ b/src/vs/workbench/api/common/extHostNotebook.ts @@ -13,7 +13,7 @@ import { IExtensionDescription } from 'vs/platform/extensions/common/extensions' import { CellKind, CellOutputKind, ExtHostNotebookShape, IMainContext, MainContext, MainThreadNotebookShape, NotebookCellOutputsSplice } from 'vs/workbench/api/common/extHost.protocol'; import { ExtHostCommands } from 'vs/workbench/api/common/extHostCommands'; import { ExtHostDocumentsAndEditors } from 'vs/workbench/api/common/extHostDocumentsAndEditors'; -import { CellEditType, CellUri, diff, ICellEditOperation, ICellInsertEdit, IErrorOutput, INotebookDisplayOrder, INotebookEditData, IOrderedMimeType, IStreamOutput, ITransformedDisplayOutputDto, mimeTypeSupportedByCore, NotebookCellsChangedEvent, NotebookCellsSplice2, sortMimeTypes } from 'vs/workbench/contrib/notebook/common/notebookCommon'; +import { CellEditType, CellUri, diff, ICellEditOperation, ICellInsertEdit, IErrorOutput, INotebookDisplayOrder, INotebookEditData, IOrderedMimeType, IStreamOutput, ITransformedDisplayOutputDto, mimeTypeSupportedByCore, NotebookCellsChangedEvent, NotebookCellsSplice2, sortMimeTypes, ICellDeleteEdit } from 'vs/workbench/contrib/notebook/common/notebookCommon'; import { Disposable as VSCodeDisposable } from './extHostTypes'; interface IObservable { @@ -425,7 +425,8 @@ export class NotebookEditorCellEdit { this._collectedEdits.push({ editType: CellEditType.Delete, - index + index, + count: 1 }); } } @@ -495,12 +496,19 @@ export class ExtHostNotebookEditor extends Disposable implements vscode.Notebook let prev = compressedEdits[prevIndex]; if (prev.editType === CellEditType.Insert && editData.edits[i].editType === CellEditType.Insert) { - if (prev.index + prev.cells.length === editData.edits[i].index) { + if (prev.index === editData.edits[i].index) { prev.cells.push(...(editData.edits[i] as ICellInsertEdit).cells); continue; } } + if (prev.editType === CellEditType.Delete && editData.edits[i].editType === CellEditType.Delete) { + if (prev.index === editData.edits[i].index) { + prev.count += (editData.edits[i] as ICellDeleteEdit).count; + continue; + } + } + compressedEdits.push(editData.edits[i]); compressedEditsIndex++; } diff --git a/src/vs/workbench/contrib/notebook/common/notebookCommon.ts b/src/vs/workbench/contrib/notebook/common/notebookCommon.ts index 83d52da64d9..3642bc68d04 100644 --- a/src/vs/workbench/contrib/notebook/common/notebookCommon.ts +++ b/src/vs/workbench/contrib/notebook/common/notebookCommon.ts @@ -224,6 +224,7 @@ export interface ICellInsertEdit { export interface ICellDeleteEdit { editType: CellEditType.Delete; index: number; + count: number; } export type ICellEditOperation = ICellInsertEdit | ICellDeleteEdit;