提交 2c70b5d5 编写于 作者: M Matt Bierner

Strict null check searchActions

上级 2c633415
...@@ -37,12 +37,16 @@ export function isSearchViewFocused(viewletService: IViewletService, panelServic ...@@ -37,12 +37,16 @@ export function isSearchViewFocused(viewletService: IViewletService, panelServic
return !!(searchView && activeElement && DOM.isAncestor(activeElement, searchView.getContainer())); return !!(searchView && activeElement && DOM.isAncestor(activeElement, searchView.getContainer()));
} }
export function appendKeyBindingLabel(label: string, keyBinding: number | ResolvedKeybinding, keyBindingService2: IKeybindingService): string { export function appendKeyBindingLabel(label: string, inputKeyBinding: number | ResolvedKeybinding | undefined, keyBindingService2: IKeybindingService): string {
if (typeof keyBinding === 'number') { if (typeof inputKeyBinding === 'number') {
const resolvedKeybindings = keyBindingService2.resolveKeybinding(createKeybinding(keyBinding, OS)); const keybinding = createKeybinding(inputKeyBinding, OS);
return doAppendKeyBindingLabel(label, resolvedKeybindings.length > 0 ? resolvedKeybindings[0] : null); if (keybinding) {
const resolvedKeybindings = keyBindingService2.resolveKeybinding(keybinding);
return doAppendKeyBindingLabel(label, resolvedKeybindings.length > 0 ? resolvedKeybindings[0] : undefined);
}
return doAppendKeyBindingLabel(label, undefined);
} else { } else {
return doAppendKeyBindingLabel(label, keyBinding); return doAppendKeyBindingLabel(label, inputKeyBinding);
} }
} }
...@@ -68,7 +72,7 @@ export function getSearchView(viewletService: IViewletService, panelService: IPa ...@@ -68,7 +72,7 @@ export function getSearchView(viewletService: IViewletService, panelService: IPa
return null; return null;
} }
function doAppendKeyBindingLabel(label: string, keyBinding: ResolvedKeybinding): string { function doAppendKeyBindingLabel(label: string, keyBinding: ResolvedKeybinding | undefined): string {
return keyBinding ? label + ' (' + keyBinding.getLabel() + ')' : label; return keyBinding ? label + ' (' + keyBinding.getLabel() + ')' : label;
} }
...@@ -232,7 +236,7 @@ export class RefreshAction extends Action { ...@@ -232,7 +236,7 @@ export class RefreshAction extends Action {
static readonly ID: string = 'search.action.refreshSearchResults'; static readonly ID: string = 'search.action.refreshSearchResults';
static LABEL: string = nls.localize('RefreshAction.label', "Refresh"); static LABEL: string = nls.localize('RefreshAction.label', "Refresh");
private searchView: SearchView; private searchView: SearchView | null;
constructor(id: string, label: string, constructor(id: string, label: string,
@IViewletService private readonly viewletService: IViewletService, @IViewletService private readonly viewletService: IViewletService,
...@@ -243,7 +247,7 @@ export class RefreshAction extends Action { ...@@ -243,7 +247,7 @@ export class RefreshAction extends Action {
} }
get enabled(): boolean { get enabled(): boolean {
return this.searchView && this.searchView.isSearchSubmitted(); return !!this.searchView && this.searchView.isSearchSubmitted();
} }
update(): void { update(): void {
...@@ -256,7 +260,7 @@ export class RefreshAction extends Action { ...@@ -256,7 +260,7 @@ export class RefreshAction extends Action {
searchView.onQueryChanged(); searchView.onQueryChanged();
} }
return Promise.resolve(null); return Promise.resolve();
} }
} }
...@@ -587,7 +591,7 @@ export class ReplaceAction extends AbstractSearchAndReplaceAction { ...@@ -587,7 +591,7 @@ export class ReplaceAction extends AbstractSearchAndReplaceAction {
private getElementToFocusAfterReplace(): Match { private getElementToFocusAfterReplace(): Match {
const navigator: INavigator<any> = this.viewer.navigate(); const navigator: INavigator<any> = this.viewer.navigate();
let fileMatched = false; let fileMatched = false;
let elementToFocus = null; let elementToFocus: any = null;
do { do {
elementToFocus = navigator.current(); elementToFocus = navigator.current();
if (elementToFocus instanceof Match) { if (elementToFocus instanceof Match) {
...@@ -611,7 +615,7 @@ export class ReplaceAction extends AbstractSearchAndReplaceAction { ...@@ -611,7 +615,7 @@ export class ReplaceAction extends AbstractSearchAndReplaceAction {
return elementToFocus; return elementToFocus;
} }
private async getElementToShowReplacePreview(elementToFocus: FileMatchOrMatch): Promise<Match> { private async getElementToShowReplacePreview(elementToFocus: FileMatchOrMatch): Promise<Match | null> {
if (this.hasSameParent(elementToFocus)) { if (this.hasSameParent(elementToFocus)) {
return <Match>elementToFocus; return <Match>elementToFocus;
} }
...@@ -686,7 +690,7 @@ function fileMatchToString(fileMatch: FileMatch, maxMatches: number): { text: st ...@@ -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[] = []; const fileResults: string[] = [];
let numMatches = 0; let numMatches = 0;
...@@ -722,7 +726,7 @@ export const copyMatchCommand: ICommandHandler = (accessor, match: RenderableMat ...@@ -722,7 +726,7 @@ export const copyMatchCommand: ICommandHandler = (accessor, match: RenderableMat
} }
}; };
function allFolderMatchesToString(folderMatches: FolderMatch[], maxMatches: number): string { function allFolderMatchesToString(folderMatches: Array<FolderMatch | BaseFolderMatch>, maxMatches: number): string {
const folderResults: string[] = []; const folderResults: string[] = [];
let numMatches = 0; let numMatches = 0;
folderMatches = folderMatches.sort(searchMatchComparer); folderMatches = folderMatches.sort(searchMatchComparer);
...@@ -743,10 +747,12 @@ export const copyAllCommand: ICommandHandler = accessor => { ...@@ -743,10 +747,12 @@ export const copyAllCommand: ICommandHandler = accessor => {
const clipboardService = accessor.get(IClipboardService); const clipboardService = accessor.get(IClipboardService);
const searchView = getSearchView(viewletService, panelService); const searchView = getSearchView(viewletService, panelService);
const root = searchView.searchResult; if (searchView) {
const root = searchView.searchResult;
const text = allFolderMatchesToString(root.folderMatches(), maxClipboardMatches); const text = allFolderMatchesToString(root.folderMatches(), maxClipboardMatches);
clipboardService.writeText(text); clipboardService.writeText(text);
}
}; };
export const clearHistoryCommand: ICommandHandler = accessor => { export const clearHistoryCommand: ICommandHandler = accessor => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册