diff --git a/src/components/quickcommandUI/SelectList.vue b/src/components/quickcommandUI/SelectList.vue
index 23d5e97..b0c610d 100644
--- a/src/components/quickcommandUI/SelectList.vue
+++ b/src/components/quickcommandUI/SelectList.vue
@@ -16,6 +16,7 @@
@click="clickOK"
:class="{
'item-selected': index === currentIndex,
+ item: true,
}"
:style="{
height: itemHeight + 'px',
@@ -26,7 +27,10 @@
- {{ item }}
+
@@ -37,10 +41,15 @@
- {{ item.title }}
- {{
- item.description
- }}
+
+
@@ -67,9 +76,9 @@
@@ -103,13 +112,18 @@ export default {
},
computed: {
matchedItems() {
- let matchedItems = this.searchWords
- ? this.items.filter((x) =>
- pinyinMatch.match(x.title ? x.title : x, this.searchWords)
- )
- : this.items;
- this.setUtoolsHeight(this.itemHeight * matchedItems.length);
- return matchedItems;
+ if (!this.searchWords) return this.items;
+
+ return this.items.filter((x) => {
+ if (this.is.json) {
+ const titleMatch = pinyinMatch.match(x.title, this.searchWords);
+ const descMatch =
+ x.description && pinyinMatch.match(x.description, this.searchWords);
+ return titleMatch || descMatch;
+ } else {
+ return pinyinMatch.match(x, this.searchWords);
+ }
+ });
},
matchedItemsSize() {
return this.matchedItems.length;
@@ -144,7 +158,9 @@ export default {
id: this.currentIndex,
text: this.matchedItems[this.currentIndex],
};
- this.is.json && selected.clickFn ? selected.clickFn(this.matchedItems[this.currentIndex].id) : this.$emit("clickOK", selected);
+ this.is.json && selected.clickFn
+ ? selected.clickFn(this.matchedItems[this.currentIndex].id)
+ : this.$emit("clickOK", selected);
this.options.options.closeOnSelect && this.hide();
},
@@ -196,7 +212,8 @@ export default {
setSubInput() {
utools.setSubInput(({ text }) => {
this.searchWords = text;
- if (this.matchedItems.length < this.currentIndex + 1) this.currentIndex = 0
+ if (this.matchedItems.length < this.currentIndex + 1)
+ this.currentIndex = 0;
}, this.options.options.placeholder);
},
@@ -216,23 +233,95 @@ export default {
document.removeEventListener(...this.$root.subInputEvent);
document.addEventListener("keydown", this.keyHandler, true);
},
+
+ highlightText(text) {
+ if (!text || !this.searchWords) return text;
+
+ const matchInfo = pinyinMatch.match(text, this.searchWords);
+ if (!matchInfo) return text;
+
+ let result = text;
+ // 从后往前替换,避免位置变化
+ for (let i = matchInfo.length - 2; i >= 0; i -= 2) {
+ const start = matchInfo[i];
+ const end = matchInfo[i + 1] + 1; // 增加1来包含最后一个字符
+ const highlightedText = `${text.slice(
+ start,
+ end
+ )}`;
+ result = result.slice(0, start) + highlightedText + result.slice(end);
+ }
+ return result;
+ },
},
};