Skip to content

Commit 10066c9

Browse files
authored
more certainty for resuming the paused emitter (microsoft#251130)
1 parent f7f1188 commit 10066c9

File tree

3 files changed

+27
-24
lines changed

3 files changed

+27
-24
lines changed

extensions/ipynb/src/test/clearOutputs.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ suite(`ipynb Clear Outputs`, () => {
2525
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
2626
});
2727

28-
test.skip('Clear outputs after opening Notebook', async () => {
28+
test('Clear outputs after opening Notebook', async () => {
2929
const cells: nbformat.ICell[] = [
3030
{
3131
cell_type: 'code',

src/vs/workbench/api/common/extHostNotebook.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape {
327327
}
328328

329329
if (document.versionId !== versionId) {
330-
throw new Error('Document version mismatch');
330+
throw new Error('Document version mismatch, expected: ' + versionId + ', actual: ' + document.versionId);
331331
}
332332

333333
if (!this._extHostFileSystem.value.isWritableFileSystem(uri.scheme)) {

src/vs/workbench/contrib/notebook/common/model/notebookTextModel.ts

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ class StackOperation implements IWorkspaceUndoRedoElement {
4949
constructor(
5050
readonly textModel: NotebookTextModel,
5151
readonly undoRedoGroup: UndoRedoGroup | undefined,
52-
private _pauseableEmitter: PauseableEmitter<NotebookTextModelChangedEvent>,
53-
private _postUndoRedo: (alternativeVersionId: string) => void,
52+
private readonly _pauseableEmitter: PauseableEmitter<NotebookTextModelChangedEvent>,
53+
private readonly _postUndoRedo: (alternativeVersionId: string) => void,
5454
selectionState: ISelectionState | undefined,
5555
beginAlternativeVersionId: string
5656
) {
@@ -621,32 +621,35 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
621621

622622
applyEdits(rawEdits: ICellEditOperation[], synchronous: boolean, beginSelectionState: ISelectionState | undefined, endSelectionsComputer: () => ISelectionState | undefined, undoRedoGroup: UndoRedoGroup | undefined, computeUndoRedo: boolean): boolean {
623623
this._pauseableEmitter.pause();
624-
this._operationManager.pushStackElement(this._alternativeVersionId, undefined);
624+
try {
625+
this._operationManager.pushStackElement(this._alternativeVersionId, undefined);
625626

626-
if (computeUndoRedo && this.isOnlyEditingMetadataOnNewCells(rawEdits)) {
627-
if (!this._operationManager.appendPreviousOperation()) {
628-
// we can't append the previous operation, so just don't compute undo/redo
629-
computeUndoRedo = false;
627+
if (computeUndoRedo && this.isOnlyEditingMetadataOnNewCells(rawEdits)) {
628+
if (!this._operationManager.appendPreviousOperation()) {
629+
// we can't append the previous operation, so just don't compute undo/redo
630+
computeUndoRedo = false;
631+
}
632+
} else if (computeUndoRedo) {
633+
this.newCellsFromLastEdit.clear();
630634
}
631-
} else if (computeUndoRedo) {
632-
this.newCellsFromLastEdit.clear();
633-
}
634635

635-
try {
636-
this._doApplyEdits(rawEdits, synchronous, computeUndoRedo, beginSelectionState, undoRedoGroup);
637-
return true;
638-
} finally {
639-
if (!this._pauseableEmitter.isEmpty) {
640-
// Update selection and versionId after applying edits.
641-
const endSelections = endSelectionsComputer();
642-
this._increaseVersionId(this._operationManager.isUndoStackEmpty() && !this._pauseableEmitter.isDirtyEvent());
636+
try {
637+
this._doApplyEdits(rawEdits, synchronous, computeUndoRedo, beginSelectionState, undoRedoGroup);
638+
return true;
639+
} finally {
640+
if (!this._pauseableEmitter.isEmpty) {
641+
// Update selection and versionId after applying edits.
642+
const endSelections = endSelectionsComputer();
643+
this._increaseVersionId(this._operationManager.isUndoStackEmpty() && !this._pauseableEmitter.isDirtyEvent());
643644

644-
// Finalize undo element
645-
this._operationManager.pushStackElement(this._alternativeVersionId, endSelections);
645+
// Finalize undo element
646+
this._operationManager.pushStackElement(this._alternativeVersionId, endSelections);
646647

647-
// Broadcast changes
648-
this._pauseableEmitter.fire({ rawEvents: [], versionId: this.versionId, synchronous: synchronous, endSelectionState: endSelections });
648+
// Broadcast changes
649+
this._pauseableEmitter.fire({ rawEvents: [], versionId: this.versionId, synchronous: synchronous, endSelectionState: endSelections });
650+
}
649651
}
652+
} finally {
650653
this._pauseableEmitter.resume();
651654
}
652655
}

0 commit comments

Comments
 (0)