diff --git a/app/src/dialog/processSystem.ts b/app/src/dialog/processSystem.ts index 86a691906..4f44f8ba4 100644 --- a/app/src/dialog/processSystem.ts +++ b/app/src/dialog/processSystem.ts @@ -21,7 +21,7 @@ import {setEmpty} from "../mobile/util/setEmpty"; import {hideAllElements, hideElements} from "../protyle/ui/hideElements"; import {App} from "../index"; import {saveScroll} from "../protyle/scroll/saveScroll"; -import {isInAndroid, isInIOS} from "../protyle/util/compatibility"; +import {isInAndroid, isInIOS, setStorageVal} from "../protyle/util/compatibility"; import {Plugin} from "../plugin"; const updateTitle = (rootID: string, tab: Tab) => { @@ -65,12 +65,14 @@ export const reloadSync = (app: App, data: { upsertRootIDs: string[], removeRoot reloadProtyle(item.editor.protyle, false); updateTitle(item.editor.protyle.block.rootID, item.parent); } else if (data.removeRootIDs.includes(item.editor.protyle.block.rootID)) { - item.parent.parent.removeTab(item.parent.id, false, false, false); + item.parent.parent.removeTab(item.parent.id, false, false); + delete window.siyuan.storage[Constants.LOCAL_FILEPOSITION][item.editor.protyle.block.rootID]; + setStorageVal(Constants.LOCAL_FILEPOSITION, window.siyuan.storage[Constants.LOCAL_FILEPOSITION]); } }); allModels.graph.forEach(item => { if (item.type === "local" && data.removeRootIDs.includes(item.rootId)) { - item.parent.parent.removeTab(item.parent.id, false, false, false); + item.parent.parent.removeTab(item.parent.id, false, false); } else if (item.type !== "local" || data.upsertRootIDs.includes(item.rootId)) { item.searchGraph(false); if (item.type === "local") { @@ -80,7 +82,7 @@ export const reloadSync = (app: App, data: { upsertRootIDs: string[], removeRoot }); allModels.outline.forEach(item => { if (item.type === "local" && data.removeRootIDs.includes(item.blockId)) { - item.parent.parent.removeTab(item.parent.id, false, false, false); + item.parent.parent.removeTab(item.parent.id, false, false); } else if (item.type !== "local" || data.upsertRootIDs.includes(item.blockId)) { fetchPost("/api/outline/getDocOutline", { id: item.blockId, @@ -94,7 +96,7 @@ export const reloadSync = (app: App, data: { upsertRootIDs: string[], removeRoot }); allModels.backlink.forEach(item => { if (item.type === "local" && data.removeRootIDs.includes(item.rootId)) { - item.parent.parent.removeTab(item.parent.id, false, false, false); + item.parent.parent.removeTab(item.parent.id, false, false); } else { item.refresh(); if (item.type === "local") { diff --git a/app/src/editor/index.ts b/app/src/editor/index.ts index 43fc75699..fa5e5a166 100644 --- a/app/src/editor/index.ts +++ b/app/src/editor/index.ts @@ -19,9 +19,9 @@ export class Editor extends Model { app: App, tab: Tab, blockId: string, + rootId?: string, // 使用 rootId 会优先使用本地 filepositon 定位 mode?: TEditorMode, action?: string[], - scrollAttr?: IScrollAttr }) { super({ app: options.app, @@ -38,19 +38,19 @@ export class Editor extends Model { private initProtyle(options: { blockId: string, action?: string[] + rootId?: string, mode?: TEditorMode, - scrollAttr?: IScrollAttr }) { this.editor = new Protyle(this.app, this.element, { action: options.action || [], blockId: options.blockId, + rootId: options.rootId, mode: options.mode, render: { title: true, background: true, scroll: true, }, - scrollAttr: options.scrollAttr, typewriterMode: true, after: (editor) => { if (window.siyuan.editorIsFullscreen) { diff --git a/app/src/editor/util.ts b/app/src/editor/util.ts index fe6e8e3c8..039577e95 100644 --- a/app/src/editor/util.ts +++ b/app/src/editor/util.ts @@ -277,7 +277,7 @@ export const openFile = async (options: IOpenFileOptions) => { createdTab = newTab(options); wnd.addTab(createdTab); if (unUpdateTab && options.removeCurrentTab) { - wnd.removeTab(unUpdateTab.id, false, true, false); + wnd.removeTab(unUpdateTab.id, false, false); } } else { createdTab = newTab(options); @@ -306,7 +306,6 @@ const getUnInitTab = (options: IOpenFileOptions) => { } else { initObj.action = options.action; } - delete initObj.scrollAttr; item.headElement.setAttribute("data-initdata", JSON.stringify(initObj)); item.parent.switchTab(item.headElement); return true; diff --git a/app/src/layout/Wnd.ts b/app/src/layout/Wnd.ts index 30eeeb349..511d212fd 100644 --- a/app/src/layout/Wnd.ts +++ b/app/src/layout/Wnd.ts @@ -682,7 +682,7 @@ export class Wnd { model.send("closews", {}); } - private removeTabAction = (id: string, closeAll = false, hasSaveScroll = true, animate = true) => { + private removeTabAction = (id: string, closeAll = false, animate = true) => { clearCounter(); this.children.find((item, index) => { if (item.id === id) { @@ -691,7 +691,7 @@ export class Wnd { item.model.beforeDestroy(); } } - if (item.model instanceof Editor && hasSaveScroll) { + if (item.model instanceof Editor) { saveScroll(item.model.editor.protyle); } if (this.children.length === 1) { @@ -787,7 +787,7 @@ export class Wnd { /// #endif }; - public removeTab(id: string, closeAll = false, needSaveScroll = true, animate = true) { + public removeTab(id: string, closeAll = false, animate = true) { for (let index = 0; index < this.children.length; index++) { const item = this.children[index]; if (item.id === id) { @@ -796,9 +796,9 @@ export class Wnd { showMessage(window.siyuan.languages.uploading); return; } - this.removeTabAction(id, closeAll, needSaveScroll, animate); + this.removeTabAction(id, closeAll, animate); } else { - this.removeTabAction(id, closeAll, needSaveScroll, animate); + this.removeTabAction(id, closeAll, animate); } return; } diff --git a/app/src/layout/tabUtil.ts b/app/src/layout/tabUtil.ts index f02dffd74..3d1beb44d 100644 --- a/app/src/layout/tabUtil.ts +++ b/app/src/layout/tabUtil.ts @@ -304,10 +304,6 @@ export const copyTab = (app: App, tab: Tab) => { } else if (!tab.model && tab.headElement) { const initData = JSON.parse(tab.headElement.getAttribute("data-initdata") || "{}"); if (initData) { - // 历史数据兼容 2023-05-24 - if (initData.scrollAttr) { - initData.scrollAttr.rootId = initData.rootId; - } model = newModelByInitData(app, newTab, initData); } } @@ -320,7 +316,7 @@ export const closeTabByType = async (tab: Tab, type: "closeOthers" | "closeAll" if (type === "closeOthers") { for (let index = 0; index < tab.parent.children.length; index++) { if (tab.parent.children[index].id !== tab.id && !tab.parent.children[index].headElement.classList.contains("item--pin")) { - await tab.parent.children[index].parent.removeTab(tab.parent.children[index].id, true, true, false); + await tab.parent.children[index].parent.removeTab(tab.parent.children[index].id, true, false); index--; } } diff --git a/app/src/layout/util.ts b/app/src/layout/util.ts index f5149838d..7a9a3e13b 100644 --- a/app/src/layout/util.ts +++ b/app/src/layout/util.ts @@ -378,7 +378,7 @@ export const JSONToLayout = (app: App, isStart: boolean) => { if (window.siyuan.config.fileTree.closeTabsOnStart && isStart) { getAllTabs().forEach(item => { if (item.headElement && !item.headElement.classList.contains("item--pin")) { - item.parent.removeTab(item.id, false, false, false); + item.parent.removeTab(item.id, false, false); } }); } @@ -402,7 +402,7 @@ export const JSONToLayout = (app: App, isStart: boolean) => { const tabId = item.getAttribute("data-id"); const tab = getInstanceById(tabId) as Tab; if (tab) { - tab.parent.removeTab(tabId, false, false, false); + tab.parent.removeTab(tabId, false, false); } } } @@ -643,10 +643,10 @@ export const newModelByInitData = (app: App, tab: Tab, json: any) => { model = new Editor({ app, tab, + rootId: json.rootId, blockId: json.blockId, mode: json.mode, action: typeof json.action === "string" ? [json.action] : json.action, - scrollAttr: json.scrollAttr, }); } return model; diff --git a/app/src/protyle/header/openTitleMenu.ts b/app/src/protyle/header/openTitleMenu.ts index c4a4fcb46..a544fdd38 100644 --- a/app/src/protyle/header/openTitleMenu.ts +++ b/app/src/protyle/header/openTitleMenu.ts @@ -27,6 +27,7 @@ import {openDocHistory} from "../../history/doc"; import {openNewWindowById} from "../../window/openNewWindow"; import {genImportMenu} from "../../menus/navigation"; import {transferBlockRef} from "../../menus/block"; +import {saveScroll} from "../scroll/saveScroll"; export const openTitleMenu = (protyle: IProtyle, position: IPosition) => { hideTooltip(); @@ -204,6 +205,7 @@ export const openTitleMenu = (protyle: IProtyle, position: IPosition) => { label: window.siyuan.languages.openByNewWindow, icon: "iconOpenWindow", click() { + saveScroll(protyle); openNewWindowById(protyle.block.rootID); } }).element); diff --git a/app/src/protyle/index.ts b/app/src/protyle/index.ts index df4d271a3..fe2c4f7cb 100644 --- a/app/src/protyle/index.ts +++ b/app/src/protyle/index.ts @@ -39,6 +39,7 @@ import {insertHTML} from "./util/insertHTML"; import {avRender} from "./render/av/render"; import {focusBlock, getEditorRange} from "./util/selection"; import {hasClosestBlock} from "./util/hasClosest"; +import {setStorageVal} from "./util/compatibility"; export class Protyle { @@ -196,7 +197,7 @@ export class Protyle { setEmpty(app); /// #else if (this.protyle.model) { - this.protyle.model.parent.parent.removeTab(this.protyle.model.parent.id, false, false); + this.protyle.model.parent.parent.removeTab(this.protyle.model.parent.id, false); } /// #endif } @@ -207,9 +208,11 @@ export class Protyle { setEmpty(app); /// #else if (this.protyle.model) { - this.protyle.model.parent.parent.removeTab(this.protyle.model.parent.id, false, false); + this.protyle.model.parent.parent.removeTab(this.protyle.model.parent.id, false); } /// #endif + delete window.siyuan.storage[Constants.LOCAL_FILEPOSITION][this.protyle.block.rootID]; + setStorageVal(Constants.LOCAL_FILEPOSITION, window.siyuan.storage[Constants.LOCAL_FILEPOSITION]); } break; } @@ -225,10 +228,10 @@ export class Protyle { removeLoading(this.protyle); return; } - if (options.scrollAttr) { + if (options.rootId) { getDocByScroll({ protyle: this.protyle, - scrollAttr: options.scrollAttr, + scrollAttr: window.siyuan.storage[Constants.LOCAL_FILEPOSITION][options.rootId], mergedOptions, cb: () => { this.afterOnGet(mergedOptions); @@ -245,19 +248,10 @@ export class Protyle { this.getDoc(mergedOptions); return; } - let scrollObj; - if (response.data.ial.scroll) { - try { - scrollObj = JSON.parse(response.data.ial.scroll.replace(/"/g, '"')); - } catch (e) { - scrollObj = undefined; - } - } - if (scrollObj) { - scrollObj.rootId = response.data.rootID; + if (window.siyuan.storage[Constants.LOCAL_FILEPOSITION][response.data.rootID]) { getDocByScroll({ protyle: this.protyle, - scrollAttr: scrollObj, + scrollAttr: window.siyuan.storage[Constants.LOCAL_FILEPOSITION][response.data.rootID], mergedOptions, cb: () => { this.afterOnGet(mergedOptions); diff --git a/app/src/protyle/scroll/saveScroll.ts b/app/src/protyle/scroll/saveScroll.ts index 87149b468..8aa5a8738 100644 --- a/app/src/protyle/scroll/saveScroll.ts +++ b/app/src/protyle/scroll/saveScroll.ts @@ -39,8 +39,8 @@ export const saveScroll = (protyle: IProtyle, getObject = false) => { if (getObject) { return attr; } - window.siyuan.storage[Constants.LOCAL_FILEPOSITION][protyle.block.rootID] = JSON.stringify(attr); - setStorageVal(Constants.LOCAL_FILEPOSITION, window.siyuan.storage[Constants.LOCAL_FILEPOSITION][protyle.block.rootID]); + window.siyuan.storage[Constants.LOCAL_FILEPOSITION][protyle.block.rootID] = attr; + setStorageVal(Constants.LOCAL_FILEPOSITION, window.siyuan.storage[Constants.LOCAL_FILEPOSITION]); }; export const getDocByScroll = (options: { diff --git a/app/src/protyle/util/onGet.ts b/app/src/protyle/util/onGet.ts index 7ed24f98a..937dbfcf4 100644 --- a/app/src/protyle/util/onGet.ts +++ b/app/src/protyle/util/onGet.ts @@ -33,7 +33,7 @@ export const onGet = (options: { if (options.data.code === 1) { // 其他报错 if (options.protyle.model) { - options.protyle.model.parent.parent.removeTab(options.protyle.model.parent.id, false, false); + options.protyle.model.parent.parent.removeTab(options.protyle.model.parent.id, false); } else { options.protyle.element.innerHTML = `