mirror of
https://github.com/microsoft/vscode.git
synced 2026-07-13 23:44:09 +01:00
await undo, reuse code (#200349)
* Revert "protect against faulty `canUndo` result"
This reverts commit cc629533b9.
* await undo, reuse code
https://github.com/microsoft/vscode/issues/200223
This commit is contained in:
@@ -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<void> {
|
||||
@@ -331,7 +331,7 @@ export class LiveStrategy extends EditModeStrategy {
|
||||
|
||||
override async undoChanges(altVersionId: number): Promise<void> {
|
||||
const { textModelN } = this._session;
|
||||
LiveStrategy._undoModelUntil(textModelN, altVersionId);
|
||||
await undoModelUntil(textModelN, altVersionId);
|
||||
}
|
||||
|
||||
override async makeProgressiveChanges(edits: ISingleEditOperation[], opts: ProgressingEditsOptions): Promise<void> {
|
||||
@@ -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<void> {
|
||||
@@ -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<void> {
|
||||
@@ -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<void> {
|
||||
while (targetAltVersion < model.getAlternativeVersionId() && model.canUndo()) {
|
||||
await model.undo();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user