diff options
| author | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-07-19 16:21:53 +1000 |
|---|---|---|
| committer | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-07-19 16:21:53 +1000 |
| commit | b4dc9e13cb56331364200a7bc427a10fd771edc9 (patch) | |
| tree | 17a7962cba65786df4c20c8650265e945bdc5020 /utils | |
| parent | launcher: better app launch (diff) | |
| download | caelestia-shell-b4dc9e13cb56331364200a7bc427a10fd771edc9.tar.gz caelestia-shell-b4dc9e13cb56331364200a7bc427a10fd771edc9.tar.bz2 caelestia-shell-b4dc9e13cb56331364200a7bc427a10fd771edc9.zip | |
launcher: better scheme search
Diffstat (limited to 'utils')
| -rw-r--r-- | utils/Searcher.qml | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/utils/Searcher.qml b/utils/Searcher.qml index 8fe8dee..053b73b 100644 --- a/utils/Searcher.qml +++ b/utils/Searcher.qml @@ -10,18 +10,31 @@ Singleton { property bool useFuzzy: false property var extraOpts: ({}) + // Extra stuff for fuzzy + property list<string> keys: [key] + property list<real> weights: [1] + readonly property var fzf: useFuzzy ? [] : new Fzf.Finder(list, Object.assign({ - selector: e => e[key] + selector }, extraOpts)) - readonly property list<var> fuzzyPrepped: useFuzzy ? list.map(e => ({ - [key]: e[key], - _item: e - })) : [] + readonly property list<var> fuzzyPrepped: useFuzzy ? list.map(e => { + const obj = { + _item: e + }; + for (const k of keys) + obj[k] = Fuzzy.prepare(e[k]); + return obj; + }) : [] function transformSearch(search: string): string { return search; } + function selector(item: var): string { + // Only for fzf + return item[key]; + } + function query(search: string): list<var> { search = transformSearch(search); if (!search) @@ -30,12 +43,13 @@ Singleton { if (useFuzzy) return Fuzzy.go(search, fuzzyPrepped, Object.assign({ all: true, - key + keys, + scoreFn: r => weights.reduce((a, w, i) => a + r[i].score * w, 0) }, extraOpts)).map(r => r.obj._item); return fzf.find(search).sort((a, b) => { if (a.score === b.score) - return a.item[key].trim().length - b.item[key].trim().length; + return selector(a.item).trim().length - selector(b.item).trim().length; return b.score - a.score; }).map(r => r.item); } |