Skip to content

Commit

Permalink
当文本框内容变动后超过2秒没有再次变动时触发搜索
Browse files Browse the repository at this point in the history
  • Loading branch information
TCOTC committed Mar 26, 2024
1 parent 8c5d5a6 commit 65021d5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "siyuan-plugin-hsr-mdzz2048-fork",
"author": "TCOTC",
"url": "https://github.com/TCOTC/siyuan-plugin-hsr-mdzz2048-fork",
"version": "0.0.12",
"version": "0.0.13",
"minAppVersion": "2.9.8",
"backends": ["windows", "linux", "darwin"],
"frontends": ["desktop", "browser-desktop"],
Expand Down
14 changes: 14 additions & 0 deletions src/Search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
v-model="searchText"
@change="highlightHitResult(searchText)"
@keyup.enter="highlightHitResult(searchText)"
@input="onSearchTextChange"
/>
</div>
{{ resultIndex + "/" + resultCount }}
Expand Down Expand Up @@ -42,6 +43,19 @@ const props = defineProps<{
element: Element,
}>()
// 当文本框内容变动后超过2秒没有再次变动时,会触发 highlightHitResult 函数
let timer: number | null = null;
function onSearchTextChange(value: string) {
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(() => {
highlightHitResult(value);
}, 2000);
}
// REF: https://juejin.cn/post/7199438741533376573
// 使用 [CSS 自定义高亮 API - Web API 接口参考 | MDN](https://developer.mozilla.org/zh-CN/docs/Web/API/CSS_Custom_Highlight_API)
// 兼容性:Chrome、Edge (105+), Safari (17.2+), firefox (寄), Electron (思源使用的版本 > 28.0, 可以使用这个 API)
Expand Down

0 comments on commit 65021d5

Please sign in to comment.