@@ -38,7 +38,7 @@ import { getMultiSelectedResources, IExplorerService } from 'vs/workbench/contri
38
38
import { ExplorerFolderContext , ExplorerRootContext , FilesExplorerFocusCondition , VIEWLET_ID as VIEWLET_ID_FILES } from 'vs/workbench/contrib/files/common/files' ;
39
39
import { AnythingQuickAccessProvider } from 'vs/workbench/contrib/search/browser/anythingQuickAccess' ;
40
40
import { registerContributions as replaceContributions } from 'vs/workbench/contrib/search/browser/replaceContributions' ;
41
- import { cancelSearch , clearHistoryCommand , clearSearchResults , CloseReplaceAction , collapseDeepestExpandedLevel , copyAllCommand , copyMatchCommand , copyPathCommand , expandAll , FindInFilesCommand , findOrReplaceInFiles , FocusNextInputAction , focusNextSearchResult , FocusPreviousInputAction , focusPreviousSearchResult , focusSearchListCommand , getSearchView , openSearchView , refreshSearch , RemoveAction , ReplaceAction , ReplaceAllAction , ReplaceAllInFolderAction , toggleCaseSensitiveCommand , togglePreserveCaseCommand , toggleRegexCommand , toggleWholeWordCommand } from 'vs/workbench/contrib/search/browser/searchActions' ;
41
+ import { cancelSearch , clearHistoryCommand , clearSearchResults , CloseReplaceAction , collapseDeepestExpandedLevel , copyAllCommand , copyMatchCommand , copyPathCommand , expandAll , FindInFilesCommand , findOrReplaceInFiles , FocusNextInputAction , focusNextSearchResult , FocusPreviousInputAction , focusPreviousSearchResult , focusSearchListCommand , getMultiSelectedSearchResources , getSearchView , openSearchView , refreshSearch , RemoveAction , ReplaceAction , ReplaceAllAction , ReplaceAllInFolderAction , toggleCaseSensitiveCommand , togglePreserveCaseCommand , toggleRegexCommand , toggleWholeWordCommand } from 'vs/workbench/contrib/search/browser/searchActions' ;
42
42
import { searchClearIcon , searchCollapseAllIcon , searchExpandAllIcon , searchRefreshIcon , searchStopIcon , searchShowAsTree , searchViewIcon , searchShowAsList } from 'vs/workbench/contrib/search/browser/searchIcons' ;
43
43
import { SearchView } from 'vs/workbench/contrib/search/browser/searchView' ;
44
44
import { registerContributions as searchWidgetContributions } from 'vs/workbench/contrib/search/browser/searchWidget' ;
@@ -47,7 +47,7 @@ import * as Constants from 'vs/workbench/contrib/search/common/constants';
47
47
import { resolveResourcesForSearchIncludes } from 'vs/workbench/services/search/common/queryBuilder' ;
48
48
import { getWorkspaceSymbols , IWorkspaceSymbol , SearchStateKey , SearchUIState } from 'vs/workbench/contrib/search/common/search' ;
49
49
import { ISearchHistoryService , SearchHistoryService } from 'vs/workbench/contrib/search/common/searchHistoryService' ;
50
- import { FileMatch , FileMatchOrMatch , FolderMatch , ISearchWorkbenchService , Match , RenderableMatch , SearchWorkbenchService } from 'vs/workbench/contrib/search/common/searchModel' ;
50
+ import { FileMatch , FileMatchOrMatch , FolderMatch , FolderMatchWithResource , ISearchWorkbenchService , Match , RenderableMatch , SearchWorkbenchService } from 'vs/workbench/contrib/search/common/searchModel' ;
51
51
import * as SearchEditorConstants from 'vs/workbench/contrib/searchEditor/browser/constants' ;
52
52
import { SearchEditor } from 'vs/workbench/contrib/searchEditor/browser/searchEditor' ;
53
53
import { IEditorService } from 'vs/workbench/services/editor/common/editorService' ;
@@ -228,6 +228,19 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
228
228
}
229
229
} ) ;
230
230
231
+ const restrictSearchToFolderFromSearch : ICommandHandler = async ( accessor , folderMatch ?: FolderMatchWithResource ) => {
232
+ return searchInFolderCommand ( accessor , false , undefined , folderMatch ) ;
233
+ } ;
234
+
235
+ const RESTRICT_SEARCH_TO_FOLDER_ID = 'search.restrictSearchToFolder' ;
236
+ KeybindingsRegistry . registerCommandAndKeybindingRule ( {
237
+ id : RESTRICT_SEARCH_TO_FOLDER_ID ,
238
+ weight : KeybindingWeight . WorkbenchContrib ,
239
+ when : ContextKeyExpr . and ( Constants . SearchViewVisibleKey , Constants . ResourceFolderFocusKey ) ,
240
+ primary : KeyMod . Shift | KeyMod . Alt | KeyCode . KeyF ,
241
+ handler : restrictSearchToFolderFromSearch
242
+ } ) ;
243
+
231
244
MenuRegistry . appendMenuItem ( MenuId . SearchContext , {
232
245
command : {
233
246
id : Constants . ReplaceActionId ,
@@ -268,6 +281,16 @@ MenuRegistry.appendMenuItem(MenuId.SearchContext, {
268
281
order : 2
269
282
} ) ;
270
283
284
+ MenuRegistry . appendMenuItem ( MenuId . SearchContext , {
285
+ group : 'search' ,
286
+ order : 3 ,
287
+ command : {
288
+ id : RESTRICT_SEARCH_TO_FOLDER_ID ,
289
+ title : nls . localize ( 'restrictResultsToFolder' , "Restrict Search to Folder..." )
290
+ } ,
291
+ when : ContextKeyExpr . and ( Constants . ResourceFolderFocusKey )
292
+ } ) ;
293
+
271
294
KeybindingsRegistry . registerCommandAndKeybindingRule ( {
272
295
id : Constants . CopyMatchCommandId ,
273
296
weight : KeybindingWeight . WorkbenchContrib ,
@@ -583,17 +606,31 @@ const FocusSearchListCommand: ICommandAction = {
583
606
} ;
584
607
MenuRegistry . addCommand ( FocusSearchListCommand ) ;
585
608
609
+ const searchInFolderFromExplorer : ICommandHandler = async ( accessor , resource ?: URI ) => {
610
+ return searchInFolderCommand ( accessor , true , resource ) ;
611
+ } ;
586
612
587
- const searchInFolderCommand : ICommandHandler = async ( accessor , resource ?: URI ) => {
613
+ const searchInFolderCommand : ICommandHandler = async ( accessor , isFromExplorer : boolean , resource ?: URI , folderMatch ?: FolderMatchWithResource ) => {
588
614
const listService = accessor . get ( IListService ) ;
589
615
const fileService = accessor . get ( IFileService ) ;
590
616
const viewsService = accessor . get ( IViewsService ) ;
591
617
const contextService = accessor . get ( IWorkspaceContextService ) ;
592
618
const commandService = accessor . get ( ICommandService ) ;
593
- const resources = getMultiSelectedResources ( resource , listService , accessor . get ( IEditorService ) , accessor . get ( IExplorerService ) ) ;
594
619
const searchConfig = accessor . get ( IConfigurationService ) . getValue < ISearchConfiguration > ( ) . search ;
595
620
const mode = searchConfig . mode ;
596
621
622
+ let resources : URI [ ] ;
623
+
624
+ if ( isFromExplorer ) {
625
+ resources = getMultiSelectedResources ( resource , listService , accessor . get ( IEditorService ) , accessor . get ( IExplorerService ) ) ;
626
+ } else {
627
+ const searchView = getSearchView ( accessor . get ( IViewsService ) ) ;
628
+ if ( ! searchView ) {
629
+ return ;
630
+ }
631
+ resources = getMultiSelectedSearchResources ( searchView . getControl ( ) , folderMatch , searchConfig ) ;
632
+ }
633
+
597
634
const resolvedResources = fileService . resolveAll ( resources . map ( resource => ( { resource } ) ) ) . then ( results => {
598
635
const folders : URI [ ] = [ ] ;
599
636
results . forEach ( result => {
@@ -619,13 +656,13 @@ const searchInFolderCommand: ICommandHandler = async (accessor, resource?: URI)
619
656
}
620
657
} ;
621
658
622
- const FIND_IN_FOLDER_ID = 'filesExplorer.findInFolder' ;
659
+ const FIND_IN_FOLDER_EXPLORER_ID = 'filesExplorer.findInFolder' ;
623
660
KeybindingsRegistry . registerCommandAndKeybindingRule ( {
624
- id : FIND_IN_FOLDER_ID ,
661
+ id : FIND_IN_FOLDER_EXPLORER_ID ,
625
662
weight : KeybindingWeight . WorkbenchContrib ,
626
663
when : ContextKeyExpr . and ( FilesExplorerFocusCondition , ExplorerFolderContext ) ,
627
664
primary : KeyMod . Shift | KeyMod . Alt | KeyCode . KeyF ,
628
- handler : searchInFolderCommand
665
+ handler : searchInFolderFromExplorer
629
666
} ) ;
630
667
631
668
const FIND_IN_WORKSPACE_ID = 'filesExplorer.findInWorkspace' ;
@@ -652,7 +689,7 @@ MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
652
689
group : '4_search' ,
653
690
order : 10 ,
654
691
command : {
655
- id : FIND_IN_FOLDER_ID ,
692
+ id : FIND_IN_FOLDER_EXPLORER_ID ,
656
693
title : nls . localize ( 'findInFolder' , "Find in Folder..." )
657
694
} ,
658
695
when : ContextKeyExpr . and ( ExplorerFolderContext )
0 commit comments