From 1de14122c5ff118a0240eb6a9d4dac26d168aa6c Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Mon, 7 Nov 2022 15:59:20 +0100 Subject: [PATCH] #440 - Filter on description --- .../components/SnippetsView/Snippets.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/dashboardWebView/components/SnippetsView/Snippets.tsx b/src/dashboardWebView/components/SnippetsView/Snippets.tsx index cf05d2c0..89641114 100644 --- a/src/dashboardWebView/components/SnippetsView/Snippets.tsx +++ b/src/dashboardWebView/components/SnippetsView/Snippets.tsx @@ -32,7 +32,14 @@ export const Snippets: React.FunctionComponent = (props: React.P const snippets = settings?.snippets || {}; const snippetKeys = useMemo(() => { const allSnippetKeys = Object.keys(snippets).sort((a, b) => a.localeCompare(b)); - return allSnippetKeys.filter((key) => key.toLowerCase().includes(snippetFilter.toLowerCase())); + return allSnippetKeys.filter((key) => { + const value = snippetFilter.toLowerCase(); + const keyValue = key.toLowerCase(); + const descriptionValue = snippets[key].description?.toLowerCase() || ''; + + // Contains in key or description, values included in key are ranked higher (sort and fuzzy search) + return keyValue.includes(value) || descriptionValue.includes(value); + }); }, [settings?.snippets, snippetFilter]); const onSnippetAdd = useCallback(() => {