Skip to content

Commit 1a73ce6

Browse files
authored
fix search selection bug (microsoft#156205)
1 parent 9d422d2 commit 1a73ce6

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/vs/workbench/contrib/search/browser/searchActions.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,8 @@ class ReplaceActionRunner {
456456

457457
async performReplace(element: FolderMatch | FileMatch | Match): Promise<any> {
458458
// since multiple elements can be selected, we need to check the type of the FolderMatch/FileMatch/Match before we perform the replace.
459-
const elementsToReplace = getElementsToOperateOnInfo(this.viewer, element, this.configurationService.getValue<ISearchConfigurationProperties>('search'));
459+
const opInfo = getElementsToOperateOnInfo(this.viewer, element, this.configurationService.getValue<ISearchConfigurationProperties>('search'));
460+
const elementsToReplace = opInfo.elements;
460461

461462
await Promise.all(elementsToReplace.map(async (elem) => {
462463
const parent = elem.parent();
@@ -585,11 +586,12 @@ export class RemoveAction extends AbstractSearchAndReplaceAction {
585586
}
586587

587588
override run(): Promise<any> {
588-
const elementsToRemove = getElementsToOperateOnInfo(this.viewer, this.element, this.configurationService.getValue<ISearchConfigurationProperties>('search'));
589+
const opInfo = getElementsToOperateOnInfo(this.viewer, this.element, this.configurationService.getValue<ISearchConfigurationProperties>('search'));
590+
const elementsToRemove = opInfo.elements;
589591

590592
const currentBottomFocusElement = elementsToRemove[elementsToRemove.length - 1];
591593

592-
const nextFocusElement = !currentBottomFocusElement || currentBottomFocusElement instanceof SearchResult || arrayContainsElementOrParent(currentBottomFocusElement, elementsToRemove) ?
594+
const nextFocusElement = opInfo.mustReselect && (!currentBottomFocusElement || currentBottomFocusElement instanceof SearchResult || arrayContainsElementOrParent(currentBottomFocusElement, elementsToRemove)) ?
593595
this.getElementToFocusAfterRemoved(this.viewer, <any>currentBottomFocusElement) :
594596
null;
595597

@@ -823,13 +825,15 @@ export const focusSearchListCommand: ICommandHandler = accessor => {
823825
});
824826
};
825827

826-
function getElementsToOperateOnInfo(viewer: WorkbenchObjectTree<RenderableMatch, void>, currElement: RenderableMatch, sortConfig: ISearchConfigurationProperties): RenderableMatch[] {
828+
function getElementsToOperateOnInfo(viewer: WorkbenchObjectTree<RenderableMatch, void>, currElement: RenderableMatch, sortConfig: ISearchConfigurationProperties): { elements: RenderableMatch[]; mustReselect: boolean } {
827829
let elements: RenderableMatch[] = viewer.getSelection().filter((x): x is RenderableMatch => x !== null).sort((a, b) => searchComparer(a, b, sortConfig.sortOrder));
828830

831+
const mustReselect = elements.includes(currElement); // this indicates whether we need to re-focus/re-select on a remove.
832+
829833
// if selection doesn't include multiple elements, just return current focus element.
830834
if (!(elements.length > 1 && elements.includes(currElement))) {
831835
elements = [currElement];
832836
}
833837

834-
return elements;
838+
return { elements, mustReselect };
835839
}

0 commit comments

Comments
 (0)