Skip to content

Commit

Permalink
v0.5.3-dev1
Browse files Browse the repository at this point in the history
  • Loading branch information
TCOTC committed Apr 18, 2024
1 parent b193d8f commit a2d937d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions src/Search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ function highlightHitResult(value: string, change: boolean) { // 搜索并高亮
// 首先,选取所有符合条件的元素
// const elements = document.querySelectorAll('.layout-tab-container > div:not(.fn__none) .protyle-wysiwyg [data-node-id]');
// 获取文档根,后续直接对全文档文本进行搜索,
const docRoot = document.querySelector('.layout-tab-container > div:not(.fn__none) .protyle-wysiwyg') as HTMLElement;
const docRoot = props.document.querySelector('.layout-tab-container > div:not(.fn__none) .protyle-wysiwyg') as HTMLElement;
//console.log("docRoot:")
//console.log(docRoot)
const docText=docRoot.textContent.toLowerCase();
const docLen=docText.length;
Expand Down Expand Up @@ -236,9 +238,15 @@ function highlightHitResult(value: string, change: boolean) { // 搜索并高亮
function scroollIntoRanges(index: number) {
const ranges = resultRange.value as Range[]
const range = ranges[index]
const parent = range.commonAncestorContainer.parentElement
parent.scrollIntoView({ behavior: 'smooth', block: "center" })
// const parent = range.commonAncestorContainer.parentElement
// parent.scrollIntoView({ behavior: 'smooth', block: "center" })
const docContentElement = props.document.querySelector('.layout-tab-container > div:not(.fn__none) >.protyle-content') as HTMLElement;
let doc_rect=docContentElement.getBoundingClientRect()
let mid_y=doc_rect.top+doc_rect.height/2
let range_rect = range.getBoundingClientRect();
docContentElement.scrollBy(0,range_rect.y-mid_y)
CSS.highlights.set("search-focus", new Highlight(range))
}
function clickLast() { // 上一个
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default class PluginHighlight extends Plugin {
}

addSearchElement() {
const edits = document.querySelectorAll(".layout__center");
const edits = document.querySelectorAll(".layout__center [data-type='wnd'].layout__wnd--active > .layout-tab-container");
console.log(edits);
edits.forEach(edit => {
const existingElement = edit.querySelector(`.${CLASS_NAME}`);
Expand Down

0 comments on commit a2d937d

Please sign in to comment.