Use fzf instead of fuse

This commit is contained in:
Matt Rubens
2025-01-15 02:19:17 -05:00
parent 89e119f121
commit 45a7566e6a
3 changed files with 18 additions and 11 deletions

View File

@@ -19,6 +19,7 @@
"debounce": "^2.1.1",
"fast-deep-equal": "^3.1.3",
"fuse.js": "^7.0.0",
"fzf": "^0.5.2",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-remark": "^2.1.0",
@@ -7475,6 +7476,11 @@
"node": ">=10"
}
},
"node_modules/fzf": {
"version": "0.5.2",
"resolved": "https://registry.npmjs.org/fzf/-/fzf-0.5.2.tgz",
"integrity": "sha512-Tt4kuxLXFKHy8KT40zwsUPUkg1CrsgY25FxA2U/j/0WgEDCk3ddc/zLTCCcbSHX9FcKtLuVaDGtGE/STWC+j3Q=="
},
"node_modules/gensync": {
"version": "1.0.0-beta.2",
"license": "MIT",

View File

@@ -14,6 +14,7 @@
"debounce": "^2.1.1",
"fast-deep-equal": "^3.1.3",
"fuse.js": "^7.0.0",
"fzf": "^0.5.2",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-remark": "^2.1.0",

View File

@@ -1,5 +1,5 @@
import { mentionRegex } from "../../../src/shared/context-mentions"
import Fuse from "fuse.js"
import { Fzf } from "fzf"
export function insertMention(
text: string,
@@ -148,19 +148,19 @@ export function getContextMenuOptions(
}
}
// Initialize Fuse instance for fuzzy search
const fuse = new Fuse(queryItems, {
keys: ["value", "label", "description"],
threshold: 0.6,
shouldSort: true,
isCaseSensitive: false,
ignoreLocation: false,
minMatchCharLength: 1,
// Create searchable strings array for fzf
const searchableItems = queryItems.map(item => ({
original: item,
searchStr: [item.value, item.label, item.description].filter(Boolean).join(' ')
}))
// Initialize fzf instance for fuzzy search
const fzf = new Fzf(searchableItems, {
selector: item => item.searchStr
})
// Get fuzzy matching items
const fuseResults = query ? fuse.search(query) : []
const matchingItems = fuseResults.map(result => result.item)
const matchingItems = query ? fzf.find(query).map(result => result.item.original) : []
// Separate matches by type
const fileMatches = matchingItems.filter(item =>