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 zoomIn?: boolean
removeCurrentTab?: boolean removeCurrentTab?: boolean
openNewTab?: boolean openNewTab?: boolean
afterOpen?: (model: Model) => void afterOpen?: (model: Model) => void,
scrollPositon?: ScrollLogicalPosition
}) => { }) => {
const response = await fetchSyncPost("/api/block/getBlockInfo", {id: options.id}); const response = await fetchSyncPost("/api/block/getBlockInfo", {id: options.id});
if (response.code === -1) { if (response.code === -1) {
@ -70,7 +71,8 @@ export const openFileById = async (options: {
keepCursor: options.keepCursor, keepCursor: options.keepCursor,
removeCurrentTab: options.removeCurrentTab, removeCurrentTab: options.removeCurrentTab,
afterOpen: options.afterOpen, 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"); highlightById(editor.editor.protyle, options.id, "start");
} else if (options.action?.includes(Constants.CB_GET_FOCUS)) { } else if (options.action?.includes(Constants.CB_GET_FOCUS)) {
if (nodeElement) { if (nodeElement) {
const isFromOutline = options.action?.includes(Constants.CB_GET_OUTLINE); const newRange = focusBlock(nodeElement, undefined, !options.action?.includes(Constants.CB_GET_OUTLINE));
const newRange = focusBlock(nodeElement, undefined, !isFromOutline);
if (newRange) { if (newRange) {
editor.editor.protyle.toolbar.range = 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(() => { editor.editor.protyle.observerLoad = new ResizeObserver(() => {
if (document.contains(nodeElement)) { if (document.contains(nodeElement)) {
scrollCenter(editor.editor.protyle); scrollCenter(editor.editor.protyle);

View file

@ -177,6 +177,7 @@ export class Outline extends Model {
openFileById({ openFileById({
app: options.app, app: options.app,
id, 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], 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({ openFileById({
app: this.app, app: this.app,
id, 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], 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; 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}; window.siyuan.storage[Constants.LOCAL_DOCINFO] = {id};
setStorageVal(Constants.LOCAL_DOCINFO, window.siyuan.storage[Constants.LOCAL_DOCINFO]); setStorageVal(Constants.LOCAL_DOCINFO, window.siyuan.storage[Constants.LOCAL_DOCINFO]);
const avPanelElement = document.querySelector(".av__panel"); 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)) { if (action.includes(Constants.CB_GET_HL)) {
highlightById(window.siyuan.mobile.editor.protyle, id); highlightById(window.siyuan.mobile.editor.protyle, id);
} else { } else {
scrollCenter(window.siyuan.mobile.editor.protyle, blockElement); scrollCenter(window.siyuan.mobile.editor.protyle, blockElement, scrollPosition);
} }
closePanel(); closePanel();
// 更新文档浏览时间 // 更新文档浏览时间

View file

@ -663,6 +663,7 @@ interface IOpenFileOptions {
data: any, data: any,
}) => import("../layout/Model").Model, // plugin 0.8.3 历史兼容 }) => import("../layout/Model").Model, // plugin 0.8.3 历史兼容
} }
scrollPositon?: ScrollLogicalPosition,
assetPath?: string, // asset 必填 assetPath?: string, // asset 必填
fileName?: string, // file 必填 fileName?: string, // file 必填
rootIcon?: string, // 文档图标 rootIcon?: string, // 文档图标