提交 e0cc8f57 编写于 作者: R Rob Lourens

Queue replace actions within a filematch because other matches in the file...

Queue replace actions within a filematch because other matches in the file should be considered stale after one replace has been executed
Fix #88282
上级 33d38a9b
...@@ -683,6 +683,8 @@ export class ReplaceAction extends AbstractSearchAndReplaceAction { ...@@ -683,6 +683,8 @@ export class ReplaceAction extends AbstractSearchAndReplaceAction {
static readonly LABEL = nls.localize('match.replace.label', "Replace"); static readonly LABEL = nls.localize('match.replace.label', "Replace");
static runQ = Promise.resolve();
constructor(private viewer: WorkbenchObjectTree<RenderableMatch>, private element: Match, private viewlet: SearchView, constructor(private viewer: WorkbenchObjectTree<RenderableMatch>, private element: Match, private viewlet: SearchView,
@IReplaceService private readonly replaceService: IReplaceService, @IReplaceService private readonly replaceService: IReplaceService,
@IKeybindingService keyBindingService: IKeybindingService, @IKeybindingService keyBindingService: IKeybindingService,
...@@ -691,26 +693,24 @@ export class ReplaceAction extends AbstractSearchAndReplaceAction { ...@@ -691,26 +693,24 @@ export class ReplaceAction extends AbstractSearchAndReplaceAction {
super(Constants.ReplaceActionId, appendKeyBindingLabel(ReplaceAction.LABEL, keyBindingService.lookupKeybinding(Constants.ReplaceActionId), keyBindingService), searchReplaceIcon.classNames); super(Constants.ReplaceActionId, appendKeyBindingLabel(ReplaceAction.LABEL, keyBindingService.lookupKeybinding(Constants.ReplaceActionId), keyBindingService), searchReplaceIcon.classNames);
} }
run(): Promise<any> { async run(): Promise<any> {
this.enabled = false; this.enabled = false;
return this.element.parent().replace(this.element).then(() => { await this.element.parent().replace(this.element);
const elementToFocus = this.getElementToFocusAfterReplace(); const elementToFocus = this.getElementToFocusAfterReplace();
if (elementToFocus) { if (elementToFocus) {
this.viewer.setFocus([elementToFocus], getSelectionKeyboardEvent()); this.viewer.setFocus([elementToFocus], getSelectionKeyboardEvent());
} }
return this.getElementToShowReplacePreview(elementToFocus); const elementToShowReplacePreview = this.getElementToShowReplacePreview(elementToFocus);
}).then(elementToShowReplacePreview => { this.viewer.domFocus();
this.viewer.domFocus();
const useReplacePreview = this.configurationService.getValue<ISearchConfiguration>().search.useReplacePreview; const useReplacePreview = this.configurationService.getValue<ISearchConfiguration>().search.useReplacePreview;
if (!useReplacePreview || !elementToShowReplacePreview || this.hasToOpenFile()) { if (!useReplacePreview || !elementToShowReplacePreview || this.hasToOpenFile()) {
this.viewlet.open(this.element, true); this.viewlet.open(this.element, true);
} else { } else {
this.replaceService.openReplacePreview(elementToShowReplacePreview, true); this.replaceService.openReplacePreview(elementToShowReplacePreview, true);
} }
});
} }
private getElementToFocusAfterReplace(): RenderableMatch { private getElementToFocusAfterReplace(): RenderableMatch {
...@@ -740,11 +740,11 @@ export class ReplaceAction extends AbstractSearchAndReplaceAction { ...@@ -740,11 +740,11 @@ export class ReplaceAction extends AbstractSearchAndReplaceAction {
return elementToFocus!; return elementToFocus!;
} }
private async getElementToShowReplacePreview(elementToFocus: RenderableMatch): Promise<Match | null> { private getElementToShowReplacePreview(elementToFocus: RenderableMatch): Match | null {
if (this.hasSameParent(elementToFocus)) { if (this.hasSameParent(elementToFocus)) {
return <Match>elementToFocus; return <Match>elementToFocus;
} }
const previousElement = await this.getPreviousElementAfterRemoved(this.viewer, this.element); const previousElement = this.getPreviousElementAfterRemoved(this.viewer, this.element);
if (this.hasSameParent(previousElement)) { if (this.hasSameParent(previousElement)) {
return <Match>previousElement; return <Match>previousElement;
} }
......
...@@ -360,9 +360,12 @@ export class FileMatch extends Disposable implements IFileMatch { ...@@ -360,9 +360,12 @@ export class FileMatch extends Disposable implements IFileMatch {
this._onChange.fire({ didRemove: true }); this._onChange.fire({ didRemove: true });
} }
replace(toReplace: Match): Promise<void> { private replaceQ = Promise.resolve();
return this.replaceService.replace(toReplace) async replace(toReplace: Match): Promise<void> {
.then(() => this.updatesMatchesForLineAfterReplace(toReplace.range().startLineNumber, false)); return this.replaceQ = this.replaceQ.finally(async () => {
await this.replaceService.replace(toReplace);
this.updatesMatchesForLineAfterReplace(toReplace.range().startLineNumber, false);
});
} }
setSelectedMatch(match: Match | null): void { setSelectedMatch(match: Match | null): void {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册