) => {
const inputValue = e.target.value;
const { cx, clearSearch } = this.props;
this.setState({ inputValue });
if (inputValue === "") {
clearSearch(cx);
}
};
renderFile = (file: Result, focused: boolean, expanded: boolean) => {
const matchesLength = file.matches.length;
const matches = ` (${matchesLength} match${matchesLength > 1 ? "es" : ""})`;
return (
{getRelativePath(file.filepath)}
{matches}
);
};
renderMatch = (match: Match, focused: boolean) => {
return (
setTimeout(() => this.selectMatchItem(match), 50)}
>
{match.line}
{highlightMatches(match)}
);
};
renderItem = (
item: Item,
depth: number,
focused: boolean,
_: any,
expanded: boolean
) => {
if (item.type === "RESULT") {
return this.renderFile(item, focused, expanded);
}
return this.renderMatch(item, focused);
};
renderResults = () => {
const { status, results } = this.props;
if (!this.props.query) {
return;
}
if (results.length) {
return (
results}
getChildren={file => file.matches || []}
itemHeight={24}
autoExpandAll={true}
autoExpandDepth={1}
autoExpandNodeChildrenLimit={100}
getParent={item => null}
getPath={getFilePath}
renderItem={this.renderItem}
focused={this.state.focusedItem}
onFocus={this.onFocus}
/>
);
}
const msg =
status === statusType.fetching
? L10N.getStr("loadingText")
: L10N.getStr("projectTextSearch.noResults");
return {msg}
;
};
renderSummary = () => {
if (this.props.query !== "") {
const resultsSummaryString = L10N.getStr("sourceSearch.resultsSummary2");
const count = this.getResultCount();
return PluralForm.get(count, resultsSummaryString).replace("#1", count);
}
return "";
};
shouldShowErrorEmoji() {
return !this.getResultCount() && this.props.status === statusType.done;
}
renderInput() {
const { cx, closeProjectSearch, status } = this.props;
return (
this.setState({ inputFocused: true })}
onBlur={() => this.setState({ inputFocused: false })}
onKeyDown={this.onKeyDown}
onHistoryScroll={this.onHistoryScroll}
handleClose={() => closeProjectSearch(cx)}
ref="searchInput"
/>
);
}
render() {
if (!this.isProjectSearchEnabled()) {
return null;
}
return (
{this.renderInput()}
{this.renderResults()}
);
}
}
ProjectSearch.contextTypes = {
shortcuts: PropTypes.object,
};
const mapStateToProps = state => ({
cx: getContext(state),
activeSearch: getActiveSearch(state),
results: getTextSearchResults(state),
query: getTextSearchQuery(state),
status: getTextSearchStatus(state),
});
export default connect(mapStateToProps, {
closeProjectSearch: actions.closeProjectSearch,
searchSources: actions.searchSources,
clearSearch: actions.clearSearch,
selectSpecificLocation: actions.selectSpecificLocation,
setActiveSearch: actions.setActiveSearch,
doSearchForHighlight: actions.doSearchForHighlight,
})(ProjectSearch);