From 2018d1523e1d488ced2ed67e338dffd0546f5fcd Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Fri, 8 Dec 2023 14:41:43 +0100 Subject: [PATCH] await undo, reuse code (#200349) * Revert "protect against faulty `canUndo` result" This reverts commit cc629533b93a583221cc634d7eab745dccf70b2f. * await undo, reuse code https://github.com/microsoft/vscode/issues/200223 --- .../browser/inlineChatStrategies.ts | 39 ++++++------------- 1 file changed, 11 insertions(+), 28 deletions(-) diff --git a/src/vs/workbench/contrib/inlineChat/browser/inlineChatStrategies.ts b/src/vs/workbench/contrib/inlineChat/browser/inlineChatStrategies.ts index 8472606b773..e1ad2764c4a 100644 --- a/src/vs/workbench/contrib/inlineChat/browser/inlineChatStrategies.ts +++ b/src/vs/workbench/contrib/inlineChat/browser/inlineChatStrategies.ts @@ -309,7 +309,7 @@ export class LiveStrategy extends EditModeStrategy { return; } const targetAltVersion = textModelNSnapshotAltVersion ?? textModelNAltVersion; - LiveStrategy._undoModelUntil(modelN, targetAltVersion); + await undoModelUntil(modelN, targetAltVersion); } override async makeChanges(edits: ISingleEditOperation[]): Promise { @@ -331,7 +331,7 @@ export class LiveStrategy extends EditModeStrategy { override async undoChanges(altVersionId: number): Promise { const { textModelN } = this._session; - LiveStrategy._undoModelUntil(textModelN, altVersionId); + await undoModelUntil(textModelN, altVersionId); } override async makeProgressiveChanges(edits: ISingleEditOperation[], opts: ProgressingEditsOptions): Promise { @@ -362,18 +362,6 @@ export class LiveStrategy extends EditModeStrategy { } } - private static _undoModelUntil(model: ITextModel, targetAltVersion: number): void { - let actualAltVersion = model.getAlternativeVersionId(); - while (targetAltVersion < actualAltVersion && model.canUndo()) { - model.undo(); - const newActualAltVersion = model.getAlternativeVersionId(); - if (actualAltVersion === newActualAltVersion) { - break; - } - actualAltVersion = newActualAltVersion; - } - } - protected _updateSummaryMessage(mappings: readonly LineRangeMapping[]) { let linesChanged = 0; for (const change of mappings) { @@ -693,7 +681,7 @@ export class LiveStrategy3 extends EditModeStrategy { return; } const targetAltVersion = textModelNSnapshotAltVersion ?? textModelNAltVersion; - LiveStrategy3._undoModelUntil(modelN, targetAltVersion); + await undoModelUntil(modelN, targetAltVersion); } override async makeChanges(edits: ISingleEditOperation[]): Promise { @@ -718,7 +706,7 @@ export class LiveStrategy3 extends EditModeStrategy { this._modifiedRangesThatHaveBeenInteractedWith.length = 0; const { textModelN } = this._session; - LiveStrategy3._undoModelUntil(textModelN, altVersionId); + await undoModelUntil(textModelN, altVersionId); } override async makeProgressiveChanges(edits: ISingleEditOperation[], opts: ProgressingEditsOptions): Promise { @@ -960,18 +948,6 @@ export class LiveStrategy3 extends EditModeStrategy { return await this._showDiff(true, false); } - private static _undoModelUntil(model: ITextModel, targetAltVersion: number): void { - let actualAltVersion = model.getAlternativeVersionId(); - while (targetAltVersion < actualAltVersion && model.canUndo()) { - model.undo(); - const newActualAltVersion = model.getAlternativeVersionId(); - if (actualAltVersion === newActualAltVersion) { - break; - } - actualAltVersion = newActualAltVersion; - } - } - protected _updateSummaryMessage(mappings: readonly LineRangeMapping[], index: number) { const changesCount = mappings.length; let message: string; @@ -994,3 +970,10 @@ export class LiveStrategy3 extends EditModeStrategy { return this._zone.widget.hasFocus(); } } + + +async function undoModelUntil(model: ITextModel, targetAltVersion: number): Promise { + while (targetAltVersion < model.getAlternativeVersionId() && model.canUndo()) { + await model.undo(); + } +}