Skip to content

Commit

Permalink
fix. #10
Browse files Browse the repository at this point in the history
修复相同文档分屏不显示,首次分屏显示滞后的问题
  • Loading branch information
OpaqueGlass committed Nov 6, 2023
1 parent 95b0afc commit 1fc2e37
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## 更新日志

### v0.2.9
- 改进:调整设置界面高度;
- 改进:默认出错重试5次;
- 修复:相同文档分屏不能显示的问题;

### v0.2.8 (2023年10月7日)
- 改进:出于兼容性考虑,对新用户默认启用覆盖主题面包屑`>`样式;
- 改进:将找不到id的错误降级为info;
Expand Down
19 changes: 14 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,9 @@ function initRetry() {
if (successFlag) {
clearInterval(g_initRetryInterval);
logPush("文档面包屑插件初始化成功");
return true;
}
return false;
}


Expand All @@ -311,7 +313,7 @@ function setObserver() {
setTimeout(async () => {
if (isDebugMode()) console.time(g_TIMER_LABLE_NAME_COMPARE);
try{
debugPush("移动端切换文档触发");
debugPush("由 移动端切换文档 触发");
// TODO: 改为动态获取id
await main([mutation.target]);
}catch(err) {
Expand All @@ -324,7 +326,7 @@ function setObserver() {
g_switchTabObserver.observe(window.document.querySelector(".protyle-background[data-node-id]"), {"attributes": true, "attributeFilter": ["data-node-id"]});
debugPush("MOBILE_LOADED");
try {
debugPush("移动端立即执行触发");
debugPush("由 移动端立即执行 触发");
main();
} catch(err) {
debugPush("移动端立即main执行", err);
Expand All @@ -338,6 +340,7 @@ function setObserver() {
console.time(g_TIMER_LABLE_NAME_COMPARE);
try{
// TODO: 改为动态获取id
debugPush("由 页签切换 触发");
await main([mutation.target]);
}catch(err) {
errorPush(err);
Expand All @@ -355,12 +358,15 @@ function setObserver() {
g_switchTabObserver.disconnect();
clearInterval(g_observerRetryInterval);
g_observerRetryInterval = setInterval(observerRetry, CONSTANTS.OBSERVER_RETRY_INTERVAL);
// setInterval将不会立即执行,这里需要立即执行
observerRetry();
}

}

});
g_observerRetryInterval = setInterval(observerRetry, CONSTANTS.OBSERVER_RETRY_INTERVAL);
observerRetry();
g_windowObserver.observe(window.siyuan.layout.centerLayout.element, {childList: true});
}
/**
Expand All @@ -379,6 +385,7 @@ function observerRetry() {
// console.time(g_TIMER_LABLE_NAME_COMPARE);
try{
// TODO
debugPush("由 页签监听重新绑定 触发");
await main(element.children);
}catch (err) {
errorPush(err);
Expand Down Expand Up @@ -680,16 +687,18 @@ async function generateElement(pathObjects, docId) {

function setAndApply(element, docId) {
// TODO: 移除已有的面包屑
const tempOldElem = window.top.document.querySelector(`.fn__flex-1.protyle:has(.protyle-background[data-node-id="${docId}"]) .og-fake-doc-breadcrumb-container`);
const tempOldElem = window.top.document.querySelector(`.layout__wnd--active .fn__flex-1.protyle:has(.protyle-background[data-node-id="${docId}"]) .og-fake-doc-breadcrumb-container`);
debugPush("setAndApply定位原有面包屑全部匹配结果", window.top.document.querySelectorAll(`.layout__wnd--active .fn__flex-1.protyle:has(.protyle-background[data-node-id="${docId}"]) .og-fake-doc-breadcrumb-container`));
debugPush("setAndApply定位文档位置全部匹配结果", window.top.document.querySelectorAll(`.layout__wnd--active .fn__flex-1.protyle:has(.protyle-background[data-node-id="${docId}"]) .protyle-breadcrumb__bar`));
if (tempOldElem) {
tempOldElem.remove();
debugPush("移除原有面包屑成功");
}

if (g_setting.oneLineBreadcrumb) {
window.top.document.querySelector(`.fn__flex-1.protyle:has(.protyle-background[data-node-id="${docId}"]) .protyle-breadcrumb__bar`).insertAdjacentElement("beforebegin",element);
window.top.document.querySelector(`.layout__wnd--active .fn__flex-1.protyle:has(.protyle-background[data-node-id="${docId}"]) .protyle-breadcrumb__bar`).insertAdjacentElement("beforebegin",element);
}else{
window.top.document.querySelector(`.fn__flex-1.protyle:has(.protyle-background[data-node-id="${docId}"]) .protyle-breadcrumb`).insertAdjacentElement("beforebegin",element);
window.top.document.querySelector(`.layout__wnd--active .fn__flex-1.protyle:has(.protyle-background[data-node-id="${docId}"]) .protyle-breadcrumb`).insertAdjacentElement("beforebegin",element);
}
debugPush("重写面包屑成功");

Expand Down

0 comments on commit 1fc2e37

Please sign in to comment.