Skip to content

Commit d13d2fc

Browse files
committed
fix #103983.
1 parent d762190 commit d13d2fc

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

src/vs/workbench/contrib/notebook/browser/notebook.contribution.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { NotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookEd
3030
import { NotebookEditorInput } from 'vs/workbench/contrib/notebook/browser/notebookEditorInput';
3131
import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';
3232
import { NotebookService } from 'vs/workbench/contrib/notebook/browser/notebookServiceImpl';
33-
import { CellKind, CellUri, NotebookDocumentBackupData, NotebookEditorPriority } from 'vs/workbench/contrib/notebook/common/notebookCommon';
33+
import { CellKind, CellUri, getCellUndoRedoComparisonKey, NotebookDocumentBackupData, NotebookEditorPriority } from 'vs/workbench/contrib/notebook/common/notebookCommon';
3434
import { NotebookProviderInfo } from 'vs/workbench/contrib/notebook/common/notebookProvider';
3535
import { IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService';
3636
import { IEditorService, IOpenEditorOverride } from 'vs/workbench/services/editor/common/editorService';
@@ -151,12 +151,7 @@ export class NotebookContribution extends Disposable implements IWorkbenchContri
151151

152152
this._register(undoRedoService.registerUriComparisonKeyComputer(CellUri.scheme, {
153153
getComparisonKey: (uri: URI): string => {
154-
const data = CellUri.parse(uri);
155-
if (!data) {
156-
return uri.toString();
157-
}
158-
159-
return data.notebook.toString();
154+
return getCellUndoRedoComparisonKey(uri);
160155
}
161156
}));
162157

src/vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { IPosition, Position } from 'vs/editor/common/core/position';
3232
import { SplitCellEdit, JoinCellEdit } from 'vs/workbench/contrib/notebook/browser/viewModel/cellEdit';
3333
import { BaseCellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/baseCellViewModel';
3434
import { PieceTreeTextBuffer } from 'vs/editor/common/model/pieceTreeTextBuffer/pieceTreeTextBuffer';
35+
import { MultiModelEditStackElement, SingleModelEditStackElement } from 'vs/editor/common/model/editStack';
3536

3637
export interface INotebookEditorViewState {
3738
editingCells: { [key: number]: boolean };
@@ -1051,12 +1052,38 @@ export class NotebookViewModel extends Disposable implements EditorFoldingStateD
10511052
});
10521053
}
10531054

1055+
async withElement(element: SingleModelEditStackElement | MultiModelEditStackElement, callback: () => Promise<void>) {
1056+
const viewCells = this._viewCells.filter(cell => element.matchesResource(cell.uri));
1057+
const refs = await Promise.all(viewCells.map(cell => cell.model.resolveTextModelRef()));
1058+
await callback();
1059+
refs.forEach(ref => ref.dispose());
1060+
}
1061+
10541062
async undo() {
1063+
const editStack = this._undoService.getElements(this.uri);
1064+
const element = editStack.past.length ? editStack.past[editStack.past.length - 1] : undefined;
1065+
1066+
if (element && element instanceof SingleModelEditStackElement || element instanceof MultiModelEditStackElement) {
1067+
return await this.withElement(element, async () => {
1068+
await this._undoService.undo(this.uri);
1069+
});
1070+
}
1071+
10551072
await this._undoService.undo(this.uri);
10561073
}
10571074

10581075
async redo() {
1076+
const editStack = this._undoService.getElements(this.uri);
1077+
const element = editStack.future[0];
1078+
1079+
if (element && element instanceof SingleModelEditStackElement || element instanceof MultiModelEditStackElement) {
1080+
return await this.withElement(element, async () => {
1081+
await this._undoService.redo(this.uri);
1082+
});
1083+
}
1084+
10591085
await this._undoService.redo(this.uri);
1086+
10601087
}
10611088

10621089
equal(notebook: NotebookTextModel) {

src/vs/workbench/contrib/notebook/common/notebookCommon.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,15 @@ export interface NotebookDataDto {
413413
readonly metadata: NotebookDocumentMetadata;
414414
}
415415

416+
export function getCellUndoRedoComparisonKey(uri: URI) {
417+
const data = CellUri.parse(uri);
418+
if (!data) {
419+
return uri.toString();
420+
}
421+
422+
return data.notebook.toString();
423+
}
424+
416425

417426
export namespace CellUri {
418427

0 commit comments

Comments
 (0)