From 468817b1a7e55b3d3d79cc93028b430ebab19372 Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Tue, 25 May 2021 10:54:59 +0100 Subject: [PATCH] Merge pull request #4085 from overleaf/ae-symbol-palette-words Improve symbol matching for multi-word input GitOrigin-RevId: a12ff1e1ccc38acab8be47fd2f5bcdca2c6c6859 --- .../components/symbol-palette-content.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/services/web/frontend/js/features/symbol-palette/components/symbol-palette-content.js b/services/web/frontend/js/features/symbol-palette/components/symbol-palette-content.js index 2e496863d7..f22759c69a 100644 --- a/services/web/frontend/js/features/symbol-palette/components/symbol-palette-content.js +++ b/services/web/frontend/js/features/symbol-palette/components/symbol-palette-content.js @@ -32,10 +32,16 @@ export default function SymbolPaletteContent({ handleSelect }) { return null } - return matchSorter(symbols, input, { - keys: ['command', 'description'], - threshold: matchSorter.rankings.CONTAINS, - }) + const words = input.trim().split(/\W+/) + + return words.reduceRight( + (symbols, word) => + matchSorter(symbols, word, { + keys: ['command', 'description'], + threshold: matchSorter.rankings.CONTAINS, + }), + symbols + ) }, [input]) const inputRef = useRef(null)