From b7de8393a7001a45ec5da82b31fa6239a67e50d9 Mon Sep 17 00:00:00 2001 From: He4eT Date: Sun, 21 Jan 2024 00:18:23 +0100 Subject: [PATCH] pages/search: enable fuzzy search --- pages/search/modules/store.js | 13 ++++++------- pages/search/search.html | 1 + 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pages/search/modules/store.js b/pages/search/modules/store.js index ece800a..e50d245 100644 --- a/pages/search/modules/store.js +++ b/pages/search/modules/store.js @@ -1,4 +1,5 @@ import * as labels from './labels.js' +const fuzzysort = window.fuzzysort export const init = ({ tabs: browserTabs, @@ -42,17 +43,15 @@ export const init = ({ browserTabs.query({ currentWindow: true, active: false }) .then(shapeTabs) .then((tabs) => tabs.reverse()) - .then((tabs) => { - void (state.tabs = tabs) - void (state.results = tabs) - }) + .then((tabs) => void (state.tabs = tabs)) /* */ const updateResults = () => { - state.results = state.query.length === 0 - ? state.tabs - : [] + state.results = fuzzysort.go(state.query, state.tabs, { + keys: ['label', 'title', 'url'], + all: true, + }).map(({obj}) => obj) } /* */ diff --git a/pages/search/search.html b/pages/search/search.html index 2c2d1eb..4743718 100644 --- a/pages/search/search.html +++ b/pages/search/search.html @@ -31,6 +31,7 @@ +