diff --git a/app/src/layout/Wnd.ts b/app/src/layout/Wnd.ts index eeb763261..fb7a9430c 100644 --- a/app/src/layout/Wnd.ts +++ b/app/src/layout/Wnd.ts @@ -312,6 +312,24 @@ export class Wnd { } }); + const initData = currentTab.headElement.getAttribute("data-initdata") + if (initData) { + const json = JSON.parse(initData); + currentTab.addModel(new Editor({ + tab: currentTab, + blockId: json.blockId, + mode: json.mode, + action: [json.action], + scrollAttr: json.scrollAttr, + })); + currentTab.headElement.removeAttribute("data-initdata"); + return; + } + + if (currentTab && target === currentTab.headElement && currentTab.model instanceof Graph) { + currentTab.model.onGraph(false); + } + if (currentTab && currentTab.model instanceof Editor) { const keepCursorId = currentTab.headElement.getAttribute("keep-cursor"); if (keepCursorId) { @@ -343,29 +361,9 @@ export class Wnd { if (update) { updatePanelByEditor(currentTab.model.editor.protyle, true, pushBack); } - - // 切换到屏幕太高的页签 https://github.com/siyuan-note/siyuan/issues/5018 - const protyle = currentTab.model.editor.protyle; - if (!protyle.scroll.element.classList.contains("fn__none") && - protyle.wysiwyg.element.lastElementChild.getAttribute("data-eof") !== "true" && - protyle.contentElement.scrollHeight > 0 && - protyle.contentElement.scrollHeight <= protyle.contentElement.clientHeight) { - fetchPost("/api/filetree/getDoc", { - id: protyle.wysiwyg.element.lastElementChild.getAttribute("data-node-id"), - mode: 2, - k: protyle.options.key || "", - size: Constants.SIZE_GET, - }, getResponse => { - onGet(getResponse, protyle, [Constants.CB_GET_APPEND, Constants.CB_GET_UNCHANGEID]); - }); - } } else { updatePanelByEditor(undefined, false); } - - if (currentTab && target === currentTab.headElement && currentTab.model instanceof Graph) { - currentTab.model.onGraph(false); - } } public addTab(tab: Tab, keepCursor = false) { diff --git a/app/src/layout/util.ts b/app/src/layout/util.ts index ec26cc736..3f2756b30 100644 --- a/app/src/layout/util.ts +++ b/app/src/layout/util.ts @@ -207,13 +207,7 @@ const JSONToCenter = (json: any, layout?: Layout | Wnd | Tab | Model) => { } (layout as Wnd).addTab(child); } else if (json.instance === "Editor" && json.blockId) { - (layout as Tab).addModel(new Editor({ - tab: (layout as Tab), - blockId: json.blockId, - mode: json.mode, - action: [json.action], - scrollAttr: json.scrollAttr, - })); + (layout as Tab).headElement.setAttribute("data-initdata", JSON.stringify(json)); } else if (json.instance === "Asset") { (layout as Tab).addModel(new Asset({ tab: (layout as Tab), @@ -308,15 +302,6 @@ export const JSONToLayout = (isStart: boolean) => { } }); } - - setTimeout(() => { - getAllModels().editor.find(item => { - if (item.headElement.classList.contains("item--focus")) { - updatePanelByEditor(item.editor.protyle, false, false); - return true; - } - }); - }, 520); }; export const layoutToJSON = (layout: Layout | Wnd | Tab | Model, json: any) => { diff --git a/app/src/protyle/scroll/event.ts b/app/src/protyle/scroll/event.ts index dfaad0454..7c4ae34d8 100644 --- a/app/src/protyle/scroll/event.ts +++ b/app/src/protyle/scroll/event.ts @@ -4,6 +4,7 @@ import {fetchPost} from "../../util/fetch"; import {onGet} from "../util/onGet"; import {showMessage} from "../../dialog/message"; import {updateHotkeyTip} from "../util/compatibility"; +import {isMobile} from "../../util/functions"; export const scrollEvent = (protyle: IProtyle, element: HTMLElement) => { let elementRect = element.getBoundingClientRect(); @@ -21,8 +22,12 @@ export const scrollEvent = (protyle: IProtyle, element: HTMLElement) => { protyle.toolbar.element.style.top = top + "px"; protyle.toolbar.element.style.display = ""; } - return; } + + if (!protyle.element.classList.contains("block__edit") && !isMobile()) { + protyle.contentElement.setAttribute("data-scrolltop", element.scrollTop.toString()); + } + if (!window.siyuan.dragElement) { // https://ld246.com/article/1649638389841 hideElements(["gutter"], protyle); } diff --git a/app/src/protyle/scroll/saveScroll.ts b/app/src/protyle/scroll/saveScroll.ts index 0a98b4cea..5ed5a4d48 100644 --- a/app/src/protyle/scroll/saveScroll.ts +++ b/app/src/protyle/scroll/saveScroll.ts @@ -9,13 +9,15 @@ export const saveScroll = (protyle: IProtyle, getObject = false) => { const attr: IScrollAttr = { startId: protyle.wysiwyg.element.firstElementChild.getAttribute("data-node-id"), endId: protyle.wysiwyg.element.lastElementChild.getAttribute("data-node-id"), - scrollTop: protyle.contentElement.scrollTop + scrollTop: protyle.contentElement.scrollTop || parseInt(protyle.contentElement.getAttribute("data-scrolltop")) || 0, } let range: Range if (getSelection().rangeCount > 0) { range = getSelection().getRangeAt(0) } - + if (!range || !protyle.wysiwyg.element.contains(range.startContainer)) { + range = protyle.toolbar.range + } if (range && protyle.wysiwyg.element.contains(range.startContainer)) { const blockElement = hasClosestBlock(range.startContainer); if (blockElement) { @@ -23,9 +25,9 @@ export const saveScroll = (protyle: IProtyle, getObject = false) => { attr.focusId = blockElement.getAttribute("data-node-id"); attr.focusStart = position.start attr.focusEnd = position.end - } } + if (protyle.block.showAll) { attr.zoomInId = protyle.block.id }