Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:zap: https://github.com/siyuan-note/siyuan/issues/10028

Vanessa2e69b019e0f7
diff --git a/app/src/layout/Wnd.ts b/app/src/layout/Wnd.ts
index 8dcd722614..c26a060e75 100644
--- a/app/src/layout/Wnd.ts
+++ b/app/src/layout/Wnd.ts
@@ -111,7 +111,11 @@ export class Wnd {
this.renderTabList(target);
break;
} else if (target.tagName === "LI" && target.getAttribute("data-id") && !pdfIsLoading(this.element)) {
- this.switchTab(target, true);
+ if (target.classList.contains("item--focus")) {
+ this.switchTab(target, true, true, false, false);
+ } else {
+ this.switchTab(target, true);
+ }
break;
}
target = target.parentElement;
@@ -701,9 +705,6 @@ export class Wnd {
item.model.beforeDestroy();
}
}
- if (item.model instanceof Editor) {
- saveScroll(item.model.editor.protyle);
- }
if (this.children.length === 1) {
this.destroyModel(this.children[0].model);
this.children = [];
@@ -754,7 +755,7 @@ export class Wnd {
}
});
if (latestHeadElement && !closeAll) {
- this.switchTab(latestHeadElement, true, true, false);
+ this.switchTab(latestHeadElement, true, true, false, false);
this.showHeading();
}
}
diff --git a/app/src/layout/index.ts b/app/src/layout/index.ts
index 62f69764cd..3b2593917a 100644
--- a/app/src/layout/index.ts
+++ b/app/src/layout/index.ts
@@ -96,7 +96,6 @@ export class Layout {
});
}
addResize(child);
- resizeTabs();
// https://ld246.com/article/1669858316295
if (this.direction === "tb") {
child.element.style.minHeight = "64px";
diff --git a/app/src/layout/tabUtil.ts b/app/src/layout/tabUtil.ts
index 447380dd2c..4c23658991 100644
--- a/app/src/layout/tabUtil.ts
+++ b/app/src/layout/tabUtil.ts
@@ -235,7 +235,6 @@ export const copyTab = (app: App, tab: Tab) => {
callback(newTab: Tab) {
let model: Model;
if (tab.model instanceof Editor) {
- saveScroll(tab.model.editor.protyle);
model = new Editor({
app,
tab: newTab,
diff --git a/app/src/protyle/header/openTitleMenu.ts b/app/src/protyle/header/openTitleMenu.ts
index 47f10d345b..dfc4f87636 100644
--- a/app/src/protyle/header/openTitleMenu.ts
+++ b/app/src/protyle/header/openTitleMenu.ts
@@ -206,7 +206,6 @@ export const openTitleMenu = (protyle: IProtyle, position: IPosition) => {
label: window.siyuan.languages.openByNewWindow,
icon: "iconOpenWindow",
click() {
- saveScroll(protyle);
openNewWindowById(protyle.block.rootID);
}
}).element);
diff --git a/app/src/protyle/scroll/saveScroll.ts b/app/src/protyle/scroll/saveScroll.ts
index 8aa5a87381..2cb7c4c85a 100644
--- a/app/src/protyle/scroll/saveScroll.ts
+++ b/app/src/protyle/scroll/saveScroll.ts
@@ -6,7 +6,7 @@ import {Constants} from "../../constants";
import {setStorageVal} from "../util/compatibility";
export const saveScroll = (protyle: IProtyle, getObject = false) => {
- if (!protyle.wysiwyg.element.firstElementChild || window.siyuan.config.readonly) {
+ if (!protyle.wysiwyg.element.firstElementChild || window.siyuan.config.readonly || protyle.element.classList.contains("fn__none")) {
// 报错或者空白页面
return undefined;
}
diff --git a/app/src/protyle/util/onGet.ts b/app/src/protyle/util/onGet.ts
index 16faca1a8b..18fafd90b0 100644
--- a/app/src/protyle/util/onGet.ts
+++ b/app/src/protyle/util/onGet.ts
@@ -391,14 +391,15 @@ const focusElementById = (protyle: IProtyle, action: string[], scrollAttr?: IScr
}
/// #endif
}
- if (scrollAttr && typeof scrollAttr.scrollTop === "number") {
+ const hasScrollTop = scrollAttr && typeof scrollAttr.scrollTop === "number"
+ if (hasScrollTop) {
protyle.contentElement.scrollTop = scrollAttr.scrollTop;
}
if (action.includes(Constants.CB_GET_FOCUS) || action.includes(Constants.CB_GET_HL) || action.includes(Constants.CB_GET_FOCUSFIRST)) {
const contentRect = protyle.contentElement.getBoundingClientRect();
const focusRect = focusElement.getBoundingClientRect();
if (contentRect.top > focusRect.top || contentRect.bottom < focusRect.bottom) {
- scrollCenter(protyle, focusElement);
+ scrollCenter(protyle, focusElement, !hasScrollTop);
}
} else {
protyle.observerLoad?.disconnect();
@@ -406,14 +407,14 @@ const focusElementById = (protyle: IProtyle, action: string[], scrollAttr?: IScr
}
// 加强定位
protyle.observerLoad = new ResizeObserver(() => {
- if (scrollAttr && typeof scrollAttr.scrollTop === "number") {
+ if (hasScrollTop) {
protyle.contentElement.scrollTop = scrollAttr.scrollTop;
}
if (action.includes(Constants.CB_GET_FOCUS) || action.includes(Constants.CB_GET_HL) || action.includes(Constants.CB_GET_FOCUSFIRST)) {
const contentRect = protyle.contentElement.getBoundingClientRect();
const focusRect = focusElement.getBoundingClientRect();
if (contentRect.top > focusRect.top || contentRect.bottom < focusRect.bottom) {
- scrollCenter(protyle, focusElement);
+ scrollCenter(protyle, focusElement, !hasScrollTop);
}
}
});
diff --git a/app/src/util/highlightById.ts b/app/src/util/highlightById.ts
index 91a257dbc8..e566b9a107 100644
--- a/app/src/util/highlightById.ts
+++ b/app/src/util/highlightById.ts
@@ -39,7 +39,7 @@ export const highlightById = (protyle: IProtyle, id: string, top = false) => {
};
export const scrollCenter = (protyle: IProtyle, nodeElement?: Element, top = false, behavior: ScrollBehavior = "auto") => {
- if (!top && getSelection().rangeCount > 0 && hasClosestBlock(getSelection().getRangeAt(0).startContainer)) {
+ if (!protyle.disabled && !top && getSelection().rangeCount > 0 && hasClosestBlock(getSelection().getRangeAt(0).startContainer)) {
const editorElement = protyle.contentElement;
const cursorTop = getSelectionPosition(editorElement).top - editorElement.getBoundingClientRect().top;
let top = 0;
diff --git a/app/src/window/openNewWindow.ts b/app/src/window/openNewWindow.ts
index f03a3452f9..abefebea19 100644
--- a/app/src/window/openNewWindow.ts
+++ b/app/src/window/openNewWindow.ts
@@ -50,29 +50,17 @@ export const openNewWindowById = (id: string, options: windowOptions = {}) => {
rootId: response.data.rootID,
mode: "wysiwyg",
instance: "Editor",
+ action: response.data.rootID === id ? Constants.CB_GET_SCROLL : Constants.CB_GET_ALL
}
};
- if (response.data.rootID === id) {
- json.children.action = Constants.CB_GET_SCROLL;
- /// #if !BROWSER
- ipcRenderer.send(Constants.SIYUAN_OPEN_WINDOW, {
- position: options.position,
- width: options.width,
- height: options.height,
- url: `${window.location.protocol}//${window.location.host}/stage/build/app/window.html?v=${Constants.SIYUAN_VERSION}&json=${encodeURIComponent(JSON.stringify(json))}`
- });
- /// #endif
- } else {
- json.children.action = Constants.CB_GET_ALL;
- /// #if !BROWSER
- ipcRenderer.send(Constants.SIYUAN_OPEN_WINDOW, {
- position: options.position,
- width: options.width,
- height: options.height,
- url: `${window.location.protocol}//${window.location.host}/stage/build/app/window.html?v=${Constants.SIYUAN_VERSION}&json=${encodeURIComponent(JSON.stringify(json))}`
- });
- /// #endif
- }
+ /// #if !BROWSER
+ ipcRenderer.send(Constants.SIYUAN_OPEN_WINDOW, {
+ position: options.position,
+ width: options.width,
+ height: options.height,
+ url: `${window.location.protocol}//${window.location.host}/stage/build/app/window.html?v=${Constants.SIYUAN_VERSION}&json=${encodeURIComponent(JSON.stringify(json))}`
+ });
+ /// #endif
});
};