From 562d022b10b152333cb69aacad630ebe648b4fed Mon Sep 17 00:00:00 2001 From: Vanessa Date: Sat, 22 Nov 2025 19:43:41 +0800 Subject: [PATCH] :recycle: https://github.com/siyuan-note/siyuan/issues/16402 --- app/src/editor/util.ts | 11 ++++++----- app/src/layout/dock/Outline.ts | 2 ++ app/src/mobile/editor.ts | 4 ++-- app/src/types/index.d.ts | 1 + 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/src/editor/util.ts b/app/src/editor/util.ts index 694bc7b08..049a008d3 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 489f1431e..c3e3a4ecd 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 f71f5f6a9..4911e0be2 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 fd3ef4573..05f4c6ea9 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, // 文档图标