diff --git a/src/vs/workbench/contrib/search/browser/searchActions.ts b/src/vs/workbench/contrib/search/browser/searchActions.ts index 3f3d57d4b49b9fd9881451d65be348902857494d..9a453c46e50ecaa665ea9e2ed27f6f7ed308a81f 100644 --- a/src/vs/workbench/contrib/search/browser/searchActions.ts +++ b/src/vs/workbench/contrib/search/browser/searchActions.ts @@ -37,12 +37,16 @@ export function isSearchViewFocused(viewletService: IViewletService, panelServic return !!(searchView && activeElement && DOM.isAncestor(activeElement, searchView.getContainer())); } -export function appendKeyBindingLabel(label: string, keyBinding: number | ResolvedKeybinding, keyBindingService2: IKeybindingService): string { - if (typeof keyBinding === 'number') { - const resolvedKeybindings = keyBindingService2.resolveKeybinding(createKeybinding(keyBinding, OS)); - return doAppendKeyBindingLabel(label, resolvedKeybindings.length > 0 ? resolvedKeybindings[0] : null); +export function appendKeyBindingLabel(label: string, inputKeyBinding: number | ResolvedKeybinding | undefined, keyBindingService2: IKeybindingService): string { + if (typeof inputKeyBinding === 'number') { + const keybinding = createKeybinding(inputKeyBinding, OS); + if (keybinding) { + const resolvedKeybindings = keyBindingService2.resolveKeybinding(keybinding); + return doAppendKeyBindingLabel(label, resolvedKeybindings.length > 0 ? resolvedKeybindings[0] : undefined); + } + return doAppendKeyBindingLabel(label, undefined); } else { - return doAppendKeyBindingLabel(label, keyBinding); + return doAppendKeyBindingLabel(label, inputKeyBinding); } } @@ -68,7 +72,7 @@ export function getSearchView(viewletService: IViewletService, panelService: IPa return null; } -function doAppendKeyBindingLabel(label: string, keyBinding: ResolvedKeybinding): string { +function doAppendKeyBindingLabel(label: string, keyBinding: ResolvedKeybinding | undefined): string { return keyBinding ? label + ' (' + keyBinding.getLabel() + ')' : label; } @@ -232,7 +236,7 @@ export class RefreshAction extends Action { static readonly ID: string = 'search.action.refreshSearchResults'; static LABEL: string = nls.localize('RefreshAction.label', "Refresh"); - private searchView: SearchView; + private searchView: SearchView | null; constructor(id: string, label: string, @IViewletService private readonly viewletService: IViewletService, @@ -243,7 +247,7 @@ export class RefreshAction extends Action { } get enabled(): boolean { - return this.searchView && this.searchView.isSearchSubmitted(); + return !!this.searchView && this.searchView.isSearchSubmitted(); } update(): void { @@ -256,7 +260,7 @@ export class RefreshAction extends Action { searchView.onQueryChanged(); } - return Promise.resolve(null); + return Promise.resolve(); } } @@ -587,7 +591,7 @@ export class ReplaceAction extends AbstractSearchAndReplaceAction { private getElementToFocusAfterReplace(): Match { const navigator: INavigator = this.viewer.navigate(); let fileMatched = false; - let elementToFocus = null; + let elementToFocus: any = null; do { elementToFocus = navigator.current(); if (elementToFocus instanceof Match) { @@ -611,7 +615,7 @@ export class ReplaceAction extends AbstractSearchAndReplaceAction { return elementToFocus; } - private async getElementToShowReplacePreview(elementToFocus: FileMatchOrMatch): Promise { + private async getElementToShowReplacePreview(elementToFocus: FileMatchOrMatch): Promise { if (this.hasSameParent(elementToFocus)) { return elementToFocus; } @@ -686,7 +690,7 @@ function fileMatchToString(fileMatch: FileMatch, maxMatches: number): { text: st }; } -function folderMatchToString(folderMatch: FolderMatch, maxMatches: number): { text: string, count: number } { +function folderMatchToString(folderMatch: FolderMatch | BaseFolderMatch, maxMatches: number): { text: string, count: number } { const fileResults: string[] = []; let numMatches = 0; @@ -722,7 +726,7 @@ export const copyMatchCommand: ICommandHandler = (accessor, match: RenderableMat } }; -function allFolderMatchesToString(folderMatches: FolderMatch[], maxMatches: number): string { +function allFolderMatchesToString(folderMatches: Array, maxMatches: number): string { const folderResults: string[] = []; let numMatches = 0; folderMatches = folderMatches.sort(searchMatchComparer); @@ -743,10 +747,12 @@ export const copyAllCommand: ICommandHandler = accessor => { const clipboardService = accessor.get(IClipboardService); const searchView = getSearchView(viewletService, panelService); - const root = searchView.searchResult; + if (searchView) { + const root = searchView.searchResult; - const text = allFolderMatchesToString(root.folderMatches(), maxClipboardMatches); - clipboardService.writeText(text); + const text = allFolderMatchesToString(root.folderMatches(), maxClipboardMatches); + clipboardService.writeText(text); + } }; export const clearHistoryCommand: ICommandHandler = accessor => {