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

Strict null check searchActions

上级 2c633415
......@@ -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<any> = 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<Match> {
private async getElementToShowReplacePreview(elementToFocus: FileMatchOrMatch): Promise<Match | null> {
if (this.hasSameParent(elementToFocus)) {
return <Match>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<FolderMatch | BaseFolderMatch>, 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 => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册