Matt Rubens 11 месяцев назад
Родитель
Сommit
45a7566e6a
3 измененных файлов с 18 добавлено и 11 удалено
  1. 6 0
      webview-ui/package-lock.json
  2. 1 0
      webview-ui/package.json
  3. 11 11
      webview-ui/src/utils/context-mentions.ts

+ 6 - 0
webview-ui/package-lock.json

@@ -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",

+ 1 - 0
webview-ui/package.json

@@ -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",

+ 11 - 11
webview-ui/src/utils/context-mentions.ts

@@ -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 =>