Skip to content

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

:recycle: https://github.com/siyuan-note/siyuan/issues/16402

Vanessa562d022b10b1
diff --git a/app/src/editor/util.ts b/app/src/editor/util.ts
index 694bc7b08b..049a008d3b 100644
--- a/app/src/editor/util.ts
+++ b/app/src/editor/util.ts
@@ -46,7 +46,8 @@ export const openFileById = async (options: {
zoomIn?: boolean
removeCurrentTab?: boolean
openNewTab?: boolean
- afterOpen?: (model: Model) => void
+ afterOpen?: (model: Model) => void,
+ scrollPositon?: ScrollLogicalPosition
}) => {
const response = await fetchSyncPost("/api/block/getBlockInfo", {id: options.id});
if (response.code === -1) {
@@ -70,7 +71,8 @@ export const openFileById = async (options: {
keepCursor: options.keepCursor,
removeCurrentTab: options.removeCurrentTab,
afterOpen: options.afterOpen,
- openNewTab: options.openNewTab
+ openNewTab: options.openNewTab,
+ scrollPositon: options.scrollPositon,
});
};
@@ -388,12 +390,11 @@ const switchEditor = (editor: Editor, options: IOpenFileOptions, allModels: IMod
highlightById(editor.editor.protyle, options.id, "start");
} else if (options.action?.includes(Constants.CB_GET_FOCUS)) {
if (nodeElement) {
- const isFromOutline = options.action?.includes(Constants.CB_GET_OUTLINE);
- const newRange = focusBlock(nodeElement, undefined, !isFromOutline);
+ const newRange = focusBlock(nodeElement, undefined, !options.action?.includes(Constants.CB_GET_OUTLINE));
if (newRange) {
editor.editor.protyle.toolbar.range = newRange;
}
- scrollCenter(editor.editor.protyle, (editor.editor.protyle.disabled || isFromOutline) ? nodeElement : null, isFromOutline ? "start" : "nearest");
+ scrollCenter(editor.editor.protyle, (editor.editor.protyle.disabled || options.scrollPositon) ? nodeElement : null, options.scrollPositon);
editor.editor.protyle.observerLoad = new ResizeObserver(() => {
if (document.contains(nodeElement)) {
scrollCenter(editor.editor.protyle);
diff --git a/app/src/layout/dock/Outline.ts b/app/src/layout/dock/Outline.ts
index 489f1431e1..c3e3a4ecd3 100644
--- a/app/src/layout/dock/Outline.ts
+++ b/app/src/layout/dock/Outline.ts
@@ -177,6 +177,7 @@ export class Outline extends Model {
openFileById({
app: options.app,
id,
+ scrollPositon: "start",
action: zoomIn ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL, Constants.CB_GET_HTML, Constants.CB_GET_OUTLINE] : [Constants.CB_GET_FOCUS, Constants.CB_GET_OUTLINE, Constants.CB_GET_SETID, Constants.CB_GET_CONTEXT, Constants.CB_GET_HTML],
});
});
@@ -930,6 +931,7 @@ export class Outline extends Model {
openFileById({
app: this.app,
id,
+ scrollPositon: "start",
action: zoomIn ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL, Constants.CB_GET_HTML, Constants.CB_GET_OUTLINE] : [Constants.CB_GET_FOCUS, Constants.CB_GET_OUTLINE, Constants.CB_GET_SETID, Constants.CB_GET_CONTEXT, Constants.CB_GET_HTML],
});
});
diff --git a/app/src/mobile/editor.ts b/app/src/mobile/editor.ts
index f71f5f6a9d..4911e0be2f 100644
--- a/app/src/mobile/editor.ts
+++ b/app/src/mobile/editor.ts
@@ -19,7 +19,7 @@ export const getCurrentEditor = () => {
return window.siyuan.mobile.popEditor || window.siyuan.mobile.editor;
};
-export const openMobileFileById = (app: App, id: string, action: TProtyleAction[] = [Constants.CB_GET_HL]) => {
+export const openMobileFileById = (app: App, id: string, action: TProtyleAction[] = [Constants.CB_GET_HL], scrollPosition?: ScrollLogicalPosition) => {
window.siyuan.storage[Constants.LOCAL_DOCINFO] = {id};
setStorageVal(Constants.LOCAL_DOCINFO, window.siyuan.storage[Constants.LOCAL_DOCINFO]);
const avPanelElement = document.querySelector(".av__panel");
@@ -44,7 +44,7 @@ export const openMobileFileById = (app: App, id: string, action: TProtyleAction[
if (action.includes(Constants.CB_GET_HL)) {
highlightById(window.siyuan.mobile.editor.protyle, id);
} else {
- scrollCenter(window.siyuan.mobile.editor.protyle, blockElement);
+ scrollCenter(window.siyuan.mobile.editor.protyle, blockElement, scrollPosition);
}
closePanel();
// 更新文档浏览时间
diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.ts
index fd3ef45734..05f4c6ea9d 100644
--- a/app/src/types/index.d.ts
+++ b/app/src/types/index.d.ts
@@ -663,6 +663,7 @@ interface IOpenFileOptions {
data: any,
}) => import("../layout/Model").Model, // plugin 0.8.3 历史兼容
}
+ scrollPositon?: ScrollLogicalPosition,
assetPath?: string, // asset 必填
fileName?: string, // file 必填
rootIcon?: string, // 文档图标