@@ -456,7 +456,8 @@ class ReplaceActionRunner {
456
456
457
457
async performReplace ( element : FolderMatch | FileMatch | Match ) : Promise < any > {
458
458
// 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 ;
460
461
461
462
await Promise . all ( elementsToReplace . map ( async ( elem ) => {
462
463
const parent = elem . parent ( ) ;
@@ -585,11 +586,12 @@ export class RemoveAction extends AbstractSearchAndReplaceAction {
585
586
}
586
587
587
588
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 ;
589
591
590
592
const currentBottomFocusElement = elementsToRemove [ elementsToRemove . length - 1 ] ;
591
593
592
- const nextFocusElement = ! currentBottomFocusElement || currentBottomFocusElement instanceof SearchResult || arrayContainsElementOrParent ( currentBottomFocusElement , elementsToRemove ) ?
594
+ const nextFocusElement = opInfo . mustReselect && ( ! currentBottomFocusElement || currentBottomFocusElement instanceof SearchResult || arrayContainsElementOrParent ( currentBottomFocusElement , elementsToRemove ) ) ?
593
595
this . getElementToFocusAfterRemoved ( this . viewer , < any > currentBottomFocusElement ) :
594
596
null ;
595
597
@@ -823,13 +825,15 @@ export const focusSearchListCommand: ICommandHandler = accessor => {
823
825
} ) ;
824
826
} ;
825
827
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 } {
827
829
let elements : RenderableMatch [ ] = viewer . getSelection ( ) . filter ( ( x ) : x is RenderableMatch => x !== null ) . sort ( ( a , b ) => searchComparer ( a , b , sortConfig . sortOrder ) ) ;
828
830
831
+ const mustReselect = elements . includes ( currElement ) ; // this indicates whether we need to re-focus/re-select on a remove.
832
+
829
833
// if selection doesn't include multiple elements, just return current focus element.
830
834
if ( ! ( elements . length > 1 && elements . includes ( currElement ) ) ) {
831
835
elements = [ currElement ] ;
832
836
}
833
837
834
- return elements ;
838
+ return { elements, mustReselect } ;
835
839
}
0 commit comments