Add keybinding to Find in Folder action. Leave handler in search.contributions.ts because of import limitations on /browser/* files

This commit is contained in:
Maksymilian Barnaś 2018-10-22 22:01:12 +02:00
parent 8244f53c1f
commit 40567e4ae3

View file

@ -20,7 +20,7 @@ import { getSelectionSearchString } from 'vs/editor/contrib/find/findController'
import { ToggleCaseSensitiveKeybinding, ToggleRegexKeybinding, ToggleWholeWordKeybinding } from 'vs/editor/contrib/find/findModel';
import * as nls from 'vs/nls';
import { ICommandAction, MenuId, MenuRegistry, SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { CommandsRegistry, ICommandHandler } from 'vs/platform/commands/common/commands';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ConfigurationScope, Extensions as ConfigurationExtensions, IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
@ -340,34 +340,44 @@ const FocusSearchListCommand: ICommandAction = {
};
MenuRegistry.addCommand(FocusSearchListCommand);
const searchInFolderCommand: ICommandHandler = (accessor, resource?: URI) => {
const listService = accessor.get(IListService);
const viewletService = accessor.get(IViewletService);
const panelService = accessor.get(IPanelService);
const fileService = accessor.get(IFileService);
const resources = getMultiSelectedResources(resource, listService, accessor.get(IEditorService));
return openSearchView(viewletService, panelService, true).then(searchView => {
if (resources && resources.length) {
return fileService.resolveFiles(resources.map(resource => ({ resource }))).then(results => {
const folders: URI[] = [];
results.forEach(result => {
if (result.success) {
folders.push(result.stat.isDirectory ? result.stat.resource : dirname(result.stat.resource));
}
});
searchView.searchInFolders(distinct(folders, folder => folder.toString()), (from, to) => relative(from, to));
});
}
return void 0;
});
};
const FIND_IN_FOLDER_ID = 'filesExplorer.findInFolder';
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: FIND_IN_FOLDER_ID,
weight: KeybindingWeight.WorkbenchContrib,
when: ContextKeyExpr.and(ExplorerFolderContext, ResourceContextKey.Scheme.isEqualTo(Schemas.file)), // todo@remote
primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.KEY_F,
handler: searchInFolderCommand
});
CommandsRegistry.registerCommand({
id: FIND_IN_FOLDER_ID,
handler: (accessor, resource?: URI) => {
const listService = accessor.get(IListService);
const viewletService = accessor.get(IViewletService);
const panelService = accessor.get(IPanelService);
const fileService = accessor.get(IFileService);
const resources = getMultiSelectedResources(resource, listService, accessor.get(IEditorService));
return openSearchView(viewletService, panelService, true).then(searchView => {
if (resources && resources.length) {
return fileService.resolveFiles(resources.map(resource => ({ resource }))).then(results => {
const folders: URI[] = [];
results.forEach(result => {
if (result.success) {
folders.push(result.stat.isDirectory ? result.stat.resource : dirname(result.stat.resource));
}
});
searchView.searchInFolders(distinct(folders, folder => folder.toString()), (from, to) => relative(from, to));
});
}
return void 0;
});
}
handler: searchInFolderCommand
});
CommandsRegistry.registerCommand({