Vanessa 2025-11-22 19:43:41 +08:00
parent 079917633c
commit 562d022b10
4 changed files with 11 additions and 7 deletions

View file

@ -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);

View file

@ -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],
});
});

View file

@ -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();
// 更新文档浏览时间

View file

@ -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, // 文档图标