Skip to content

Commit

Permalink
搜索结果索引计数可以循环、只搜索在文档区域内的文本(不包含界面和文档标题)
Browse files Browse the repository at this point in the history
  • Loading branch information
TCOTC committed Mar 26, 2024
1 parent 916a77c commit 1f72b68
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

- 适配其他主题和插件,不再被覆盖
- 高亮结果文本滚动到页面中央
- 搜索结果索引计数为 0 时点击「上一个」,计数会从末尾开始
- 搜索结果索引计数可以循环

修复:

Expand Down
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.7",
"version": "0.0.8",
"minAppVersion": "2.9.8",
"backends": ["windows", "linux", "darwin"],
"frontends": ["desktop", "browser-desktop"],
Expand Down
12 changes: 7 additions & 5 deletions src/Search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function highlightHitResult(value: string) {
// 自动重置搜索结果索引计数为 0
resultIndex.value = 0
/*
// 创建 createTreeWalker 迭代器,用于遍历文本节点,保存到一个数组
const treeWalker = document.createTreeWalker(props.document, NodeFilter.SHOW_TEXT)
const allTextNodes: Node[] = []
Expand All @@ -58,10 +58,9 @@ function highlightHitResult(value: string) {
allTextNodes.push(currentNode)
currentNode = treeWalker.nextNode()
}
*/
// 可能有问题,回滚一下看看
// 上面的换成下面这个:
/*
// 首先,选取所有符合条件的元素
const elements = document.querySelectorAll('.protyle-wysiwyg [data-node-id]');
Expand All @@ -78,7 +77,7 @@ function highlightHitResult(value: string) {
}
});
// 此时,allTextNodes 数组包含了所有符合条件元素内的文本节点
*/
Expand Down Expand Up @@ -143,7 +142,7 @@ function clickLast() {
if (resultIndex.value > 1) {
resultIndex.value = resultIndex.value - 1
}
else if (resultIndex.value < 1) {
else if (resultIndex.value <= 1) {
resultIndex.value = resultCount.value
}
scroollIntoRanges(resultIndex.value -1)
Expand All @@ -152,6 +151,9 @@ function clickNext() {
if (resultIndex.value < resultCount.value) {
resultIndex.value = resultIndex.value + 1
}
else if (resultIndex.value >= resultCount.value) {
resultIndex.value = 1
}
scroollIntoRanges(resultIndex.value -1)
}
function clickClose() {
Expand Down
3 changes: 2 additions & 1 deletion src/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
z-index: 5;
}
.highlight-search-result .search-dialog .search-tools #search-tools-close {
transform: scale(0.84,0.84);
height: 11.85px;
width: 11.85px;
}
::highlight(search-results) {
background-color: rgb(235 235 5);
Expand Down

0 comments on commit 1f72b68

Please sign in to comment.