diff options
Diffstat (limited to 'plugins/base')
3 files changed, 15 insertions, 8 deletions
diff --git a/plugins/base/frontend/src/main/components/search/dokkaFuzzyFilter.tsx b/plugins/base/frontend/src/main/components/search/dokkaFuzzyFilter.tsx index 164a925a..804cc0bf 100644 --- a/plugins/base/frontend/src/main/components/search/dokkaFuzzyFilter.tsx +++ b/plugins/base/frontend/src/main/components/search/dokkaFuzzyFilter.tsx @@ -2,7 +2,8 @@ import {Select} from "@jetbrains/ring-ui"; import {Option, OptionWithHighlightComponent, OptionWithSearchResult, SearchRank} from "./types"; import fuzzyHighlight from '@jetbrains/ring-ui/components/global/fuzzy-highlight.js' import React from "react"; -import {SearchResultRow} from "./searchResultRow"; +import {SearchResultRow, signatureFromSearchResult} from "./searchResultRow"; +import _ from "lodash"; const orderRecords = (records: OptionWithSearchResult[], searchPhrase: string): OptionWithSearchResult[] => { return records.sort((a: OptionWithSearchResult, b: OptionWithSearchResult) => { @@ -38,6 +39,11 @@ const highlightMatchedPhrases = (records: OptionWithSearchResult[]): OptionWithH }) } +const hasAnyMatchedPhraseLongerThan = (searchResult: OptionWithSearchResult, length: number): boolean => { + const values = _.chunk(signatureFromSearchResult(searchResult).split("**"), 2).map(([txt, matched]) => matched ? matched.length >= length : null) + return values.reduce((acc, element) => acc || element) +} + export class DokkaFuzzyFilterComponent extends Select { componentDidUpdate(prevProps, prevState) { super.componentDidUpdate(prevProps, prevState) @@ -66,7 +72,7 @@ export class DokkaFuzzyFilterComponent extends Select { rank: SearchRank.NameMatch } }) - .filter((record: OptionWithSearchResult) => record.matched) + .filter((record: OptionWithSearchResult) => record.matched && (hasAnyMatchedPhraseLongerThan(record, 3) || filterPhrase.length < 3)) this.props.onFilter(filterPhrase) diff --git a/plugins/base/frontend/src/main/components/search/search.tsx b/plugins/base/frontend/src/main/components/search/search.tsx index ef26c662..ce1ac8b4 100644 --- a/plugins/base/frontend/src/main/components/search/search.tsx +++ b/plugins/base/frontend/src/main/components/search/search.tsx @@ -27,6 +27,7 @@ const WithFuzzySearchFilterComponent: React.FC<Props> = ({data}: Props) => { type={Select.Type.CUSTOM} clear renderOptimization + disableScrollToActive selected={selected} data={data} popupClassName={"popup-wrapper"} diff --git a/plugins/base/frontend/src/main/components/search/searchResultRow.tsx b/plugins/base/frontend/src/main/components/search/searchResultRow.tsx index 83dd2bcb..5910eec4 100644 --- a/plugins/base/frontend/src/main/components/search/searchResultRow.tsx +++ b/plugins/base/frontend/src/main/components/search/searchResultRow.tsx @@ -10,14 +10,14 @@ const Highlighter: React.FC<HighlighterProps> = ({label}: HighlighterProps) => { return <strong>{label}</strong> } -export const SearchResultRow: React.FC<SearchProps> = ({searchResult}: SearchProps) => { - const signatureFromSearchResult = (searchResult: OptionWithSearchResult): string => { - if(searchResult.rank == SearchRank.SearchKeyMatch){ - return searchResult.name.replace(searchResult.searchKey, searchResult.highlight) - } - return searchResult.highlight +export const signatureFromSearchResult = (searchResult: OptionWithSearchResult): string => { + if(searchResult.rank == SearchRank.SearchKeyMatch){ + return searchResult.name.replace(searchResult.searchKey, searchResult.highlight) } + return searchResult.highlight +} +export const SearchResultRow: React.FC<SearchProps> = ({searchResult}: SearchProps) => { /* This is a work-around for an issue: https://youtrack.jetbrains.com/issue/RG-2108 */ |