aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/frontend/src/main
diff options
context:
space:
mode:
authorMarcin Aman <maman@virtuslab.com>2020-09-16 10:01:22 +0200
committerPaweł Marks <Kordyjan@users.noreply.github.com>2020-09-17 11:36:14 +0200
commitbba797735a392c6c829a5333823b66a092b96bb4 (patch)
tree2d2b6a80fe2ee33ef4a42e58e14117c796b05096 /plugins/base/frontend/src/main
parentbea6d7d6ad691ca3db180d4cbd5dfb6575ecda03 (diff)
downloaddokka-bba797735a392c6c829a5333823b66a092b96bb4.tar.gz
dokka-bba797735a392c6c829a5333823b66a092b96bb4.tar.bz2
dokka-bba797735a392c6c829a5333823b66a092b96bb4.zip
Fix scrolling to relevant records in search, filter all that doesnt match required amout of letters
Diffstat (limited to 'plugins/base/frontend/src/main')
-rw-r--r--plugins/base/frontend/src/main/components/search/dokkaFuzzyFilter.tsx10
-rw-r--r--plugins/base/frontend/src/main/components/search/search.tsx1
-rw-r--r--plugins/base/frontend/src/main/components/search/searchResultRow.tsx12
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
*/