diff --git a/app/src/constants.ts b/app/src/constants.ts index 9053672c5..f8aa9cf00 100644 --- a/app/src/constants.ts +++ b/app/src/constants.ts @@ -53,7 +53,7 @@ export abstract class Constants { // localstorage public static readonly LOCAL_SEARCHEDATA = "local-searchedata"; public static readonly LOCAL_SEARCHETABDATA = "local-searchetabdata"; - public static readonly LOCAL_DOC = "local-doc"; + public static readonly LOCAL_DOCINFO = "local-docinfo"; public static readonly LOCAL_DAILYNOTEID = "local-dailynoteid"; public static readonly LOCAL_HISTORYNOTEID = "local-historynoteid"; public static readonly LOCAL_CODELANG = "local-codelang"; diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.ts index fb71f3bf9..9e1edeaf6 100644 --- a/app/src/menus/protyle.ts +++ b/app/src/menus/protyle.ts @@ -329,6 +329,11 @@ export const zoomOut = (protyle: IProtyle, id: string, focusId?: string, isPushB } } if (window.siyuan.mobileEditor) { + window.localStorage.setItem(Constants.LOCAL_DOCINFO, JSON.stringify({ + id, + hasContext: id === protyle.block.rootID, + action: id === protyle.block.rootID ? [Constants.CB_GET_HL] : [Constants.CB_GET_ALL] + })); window.siyuan.backStack.push({ id: protyle.block.id, scrollTop: protyle.contentElement.scrollTop, diff --git a/app/src/mobile/editor.ts b/app/src/mobile/editor.ts index 1d4d49a94..8fd17e407 100644 --- a/app/src/mobile/editor.ts +++ b/app/src/mobile/editor.ts @@ -12,6 +12,7 @@ import {lockFile} from "../dialog/processSystem"; import {hasClosestByAttribute} from "../protyle/util/hasClosest"; export const openMobileFileById = (id: string, hasContext?: boolean, action = [Constants.CB_GET_HL], pushStack = true) => { + window.localStorage.setItem(Constants.LOCAL_DOCINFO, JSON.stringify({id, hasContext, action})); if (window.siyuan.mobileEditor) { let blockElement; Array.from(window.siyuan.mobileEditor.protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${id}"]`)).find(item => { @@ -83,7 +84,6 @@ export const openMobileFileById = (id: string, hasContext?: boolean, action = [C (document.getElementById("toolbarName") as HTMLInputElement).value = data.data.rootTitle; setEditor(); closePanel(); - window.localStorage.setItem(Constants.LOCAL_DOC, id); if (pushStack) { window.siyuan.backStack.push({ id, diff --git a/app/src/mobile/util/initFramework.ts b/app/src/mobile/util/initFramework.ts index 5d598fbb6..0048fce69 100644 --- a/app/src/mobile/util/initFramework.ts +++ b/app/src/mobile/util/initFramework.ts @@ -91,14 +91,14 @@ export const initFramework = () => { }); initEditorName(); if (getOpenNotebookCount() > 0) { - const id = window.localStorage.getItem(Constants.LOCAL_DOC) || ""; - fetchPost("/api/block/checkBlockExist", {id}, existResponse => { + const localDoc = JSON.parse(window.localStorage.getItem(Constants.LOCAL_DOCINFO) || '{"id": ""}'); + fetchPost("/api/block/checkBlockExist", {id: localDoc.id}, existResponse => { if (existResponse.data) { - openMobileFileById(id); + openMobileFileById(localDoc.id, localDoc.hasContext, localDoc.action); } else { fetchPost("/api/block/getRecentUpdatedBlocks", {}, (response) => { if (response.data.length !== 0) { - openMobileFileById(response.data[0].id); + openMobileFileById(response.data[0].id, true); } else { setEmpty(); } diff --git a/app/src/mobile/util/search.ts b/app/src/mobile/util/search.ts index 1062e4f82..6e05766d4 100644 --- a/app/src/mobile/util/search.ts +++ b/app/src/mobile/util/search.ts @@ -77,7 +77,7 @@ export const popSearch = (modelElement: HTMLElement, modelMainElement: HTMLEleme preventScroll(window.siyuan.mobileEditor.protyle); } fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => { - openMobileFileById(id, !foldResponse.data); + openMobileFileById(id, !foldResponse.data, foldResponse.data ? [Constants.CB_GET_ALL, Constants.CB_GET_HL] : [Constants.CB_GET_HL]); }); closePanel(); event.preventDefault(); diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts index 304a7bbb5..50f94abd1 100644 --- a/app/src/protyle/wysiwyg/index.ts +++ b/app/src/protyle/wysiwyg/index.ts @@ -1251,10 +1251,11 @@ export class WYSIWYG { } else if (aElement) { refBlockId = aElement.getAttribute("data-href").substring(16, 38); } - if (isMobile()) { - openMobileFileById(refBlockId, false, [Constants.CB_GET_ALL]); - } else { - fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => { + + fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => { + if (isMobile()) { + openMobileFileById(refBlockId, !foldResponse.data, foldResponse.data ? [Constants.CB_GET_ALL, Constants.CB_GET_HL] : [Constants.CB_GET_HL]); + } else { if (window.siyuan.shiftIsPressed) { openFileById({ id: refBlockId, @@ -1287,8 +1288,8 @@ export class WYSIWYG { zoomIn: foldResponse.data }); } - }); - } + } + }); if (protyle.model) { // 打开双链需记录到后退中 https://github.com/siyuan-note/insider/issues/801 let blockElement: HTMLElement | false; @@ -1397,7 +1398,7 @@ export class WYSIWYG { const embedItemElement = hasClosestByClassName(event.target, "protyle-wysiwyg__embed"); if (embedItemElement) { if (isMobile()) { - openMobileFileById(embedItemElement.getAttribute("data-id"), false, [Constants.CB_GET_ALL], true); + openMobileFileById(embedItemElement.getAttribute("data-id"), false, [Constants.CB_GET_ALL]); } else if (!protyle.disabled) { window.siyuan.blockPanels.push(new BlockPanel({ targetElement: embedItemElement,