diff --git a/app/src/mobile/dock/MobileBacklinks.ts b/app/src/mobile/dock/MobileBacklinks.ts index d2f257a92..475673cef 100644 --- a/app/src/mobile/dock/MobileBacklinks.ts +++ b/app/src/mobile/dock/MobileBacklinks.ts @@ -44,14 +44,14 @@ export class MobileBacklinks { element: this.element.querySelector(".backlinkList") as HTMLElement, data: null, click(element: HTMLElement) { - openMobileFileById(app, element.getAttribute("data-node-id"), [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]); + openMobileFileById(app, element.getAttribute("data-node-id"), [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]); } }); this.mTree = new Tree({ element: this.element.querySelector(".backlinkMList") as HTMLElement, data: null, click: (element) => { - openMobileFileById(app, element.getAttribute("data-node-id"), [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]); + openMobileFileById(app, element.getAttribute("data-node-id"), [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]); }, }); this.element.addEventListener("click", (event) => { diff --git a/app/src/mobile/dock/MobileFiles.ts b/app/src/mobile/dock/MobileFiles.ts index 444a5dfda..68fddc7cc 100644 --- a/app/src/mobile/dock/MobileFiles.ts +++ b/app/src/mobile/dock/MobileFiles.ts @@ -215,7 +215,7 @@ export class MobileFiles extends Model { } else if (target.tagName === "LI") { this.setCurrent(target); if (target.getAttribute("data-type") === "navigation-file") { - openMobileFileById(app, target.getAttribute("data-node-id")); + openMobileFileById(app, target.getAttribute("data-node-id"), [Constants.CB_GET_SCROLL, Constants.CB_GET_HL]); } else if (target.getAttribute("data-type") === "navigation-root") { const ulElement = hasTopClosestByTag(target, "UL"); if (ulElement) { diff --git a/app/src/mobile/dock/MobileOutline.ts b/app/src/mobile/dock/MobileOutline.ts index 4de1c9067..e3a6c5270 100644 --- a/app/src/mobile/dock/MobileOutline.ts +++ b/app/src/mobile/dock/MobileOutline.ts @@ -35,7 +35,7 @@ export class MobileOutline { document.getElementById(id)?.scrollIntoView(); } else { checkFold(id, (zoomIn) => { - openMobileFileById(app, id, zoomIn ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL, Constants.CB_GET_HTML] : [Constants.CB_GET_FOCUS, Constants.CB_GET_SETID, Constants.CB_GET_CONTEXT, Constants.CB_GET_HTML]); + openMobileFileById(app, id, zoomIn ? [Constants.CB_GET_HL, Constants.CB_GET_ALL, Constants.CB_GET_HTML] : [Constants.CB_GET_HL, 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 a7394d544..87bc41c07 100644 --- a/app/src/mobile/editor.ts +++ b/app/src/mobile/editor.ts @@ -13,6 +13,7 @@ import {pushBack} from "./util/MobileBackFoward"; import {setStorageVal} from "../protyle/util/compatibility"; import {showMessage} from "../dialog/message"; import {App} from "../index"; +import {getDocByScroll, saveScroll} from "../protyle/scroll/saveScroll"; export const getCurrentEditor = () => { return window.siyuan.mobile.popEditor || window.siyuan.mobile.editor; @@ -22,6 +23,7 @@ export const openMobileFileById = (app: App, id: string, action = [Constants.CB_ window.siyuan.storage[Constants.LOCAL_DOCINFO] = {id}; setStorageVal(Constants.LOCAL_DOCINFO, window.siyuan.storage[Constants.LOCAL_DOCINFO]); if (window.siyuan.mobile.editor) { + saveScroll(window.siyuan.mobile.editor.protyle); hideElements(["toolbar", "hint", "util"], window.siyuan.mobile.editor.protyle); if (window.siyuan.mobile.editor.protyle.contentElement.classList.contains("fn__none")) { setEditMode(window.siyuan.mobile.editor.protyle, "wysiwyg"); @@ -46,32 +48,41 @@ export const openMobileFileById = (app: App, id: string, action = [Constants.CB_ showMessage(data.msg); return; } + const protyleOptions: IOptions = { + blockId: id, + rootId: data.data.rootID, + action, + render: { + scroll: true, + background: true, + gutter: true, + }, + typewriterMode: true, + preview: { + actions: ["mp-wechat", "zhihu"] + } + } if (window.siyuan.mobile.editor) { pushBack(); addLoading(window.siyuan.mobile.editor.protyle); - fetchPost("/api/filetree/getDoc", { - id, - size: action.includes(Constants.CB_GET_ALL) ? Constants.SIZE_GET_MAX : window.siyuan.config.editor.dynamicLoadBlocks, - mode: action.includes(Constants.CB_GET_CONTEXT) ? 3 : 0, - }, getResponse => { - onGet({data: getResponse, protyle: window.siyuan.mobile.editor.protyle, action}); - }); + if (action.includes(Constants.CB_GET_SCROLL)) { + getDocByScroll({ + protyle: window.siyuan.mobile.editor.protyle, + scrollAttr: window.siyuan.storage[Constants.LOCAL_FILEPOSITION][data.data.rootID], + mergedOptions: protyleOptions + }); + } else { + fetchPost("/api/filetree/getDoc", { + id, + size: action.includes(Constants.CB_GET_ALL) ? Constants.SIZE_GET_MAX : window.siyuan.config.editor.dynamicLoadBlocks, + mode: action.includes(Constants.CB_GET_CONTEXT) ? 3 : 0, + }, getResponse => { + onGet({data: getResponse, protyle: window.siyuan.mobile.editor.protyle, action}); + }); + } window.siyuan.mobile.editor.protyle.undo.clear(); } else { - window.siyuan.mobile.editor = new Protyle(app, document.getElementById("editor"), { - blockId: id, - rootId: data.data.rootID, - action, - render: { - scroll: true, - background: true, - gutter: true, - }, - typewriterMode: true, - preview: { - actions: ["mp-wechat", "zhihu"] - } - }); + window.siyuan.mobile.editor = new Protyle(app, document.getElementById("editor"), protyleOptions); } (document.getElementById("toolbarName") as HTMLInputElement).value = data.data.rootTitle === "Untitled" ? "" : data.data.rootTitle; setEditor(); diff --git a/app/src/mobile/index.ts b/app/src/mobile/index.ts index 38ff8811b..762acf15f 100644 --- a/app/src/mobile/index.ts +++ b/app/src/mobile/index.ts @@ -152,7 +152,7 @@ window.hideKeyboardToolbar = hideKeyboardToolbar; window.openFileByURL = (openURL) => { if (openURL && isSYProtocol(openURL)) { openMobileFileById(siyuanApp, getIdFromSYProtocol(openURL), - getSearch("focus", openURL) === "1" ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]); + getSearch("focus", openURL) === "1" ? [Constants.CB_GET_ALL, Constants.CB_GET_HL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]); return true; } return false; diff --git a/app/src/mobile/util/initFramework.ts b/app/src/mobile/util/initFramework.ts index 9c11fb1c3..d977c1054 100644 --- a/app/src/mobile/util/initFramework.ts +++ b/app/src/mobile/util/initFramework.ts @@ -170,7 +170,7 @@ export const initFramework = (app: App, isStart: boolean) => { const idZoomIn = getIdZoomInByPath(); if (idZoomIn.id) { openMobileFileById(app, idZoomIn.id, - idZoomIn.isZoomIn ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]); + idZoomIn.isZoomIn ? [Constants.CB_GET_ALL, Constants.CB_GET_HL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]); return; } if (window.siyuan.config.fileTree.closeTabsOnStart && isStart) { diff --git a/app/src/mobile/util/onMessage.ts b/app/src/mobile/util/onMessage.ts index f613bdcb3..7ad4b5b3d 100644 --- a/app/src/mobile/util/onMessage.ts +++ b/app/src/mobile/util/onMessage.ts @@ -25,7 +25,7 @@ export const onMessage = (app: App, data: IWebSocketData) => { } break; case "openFileById": - openMobileFileById(app, data.data.id, [Constants.CB_GET_FOCUS]); + openMobileFileById(app, data.data.id, [Constants.CB_GET_HL]); break; case"txerr": transactionError();