From ec29bc7071f996bc07cf38d826aab99fadb2f9f9 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Tue, 28 Nov 2023 21:17:19 +0800 Subject: [PATCH] :art: fix https://github.com/siyuan-note/siyuan/issues/9767 --- app/src/config/editor.ts | 4 +--- app/src/mobile/util/MobileBackFoward.ts | 15 ++----------- app/src/protyle/index.ts | 4 ++-- app/src/protyle/util/onGet.ts | 28 ++++++++++++++----------- 4 files changed, 21 insertions(+), 30 deletions(-) diff --git a/app/src/config/editor.ts b/app/src/config/editor.ts index acb85e8bd..b989208b9 100644 --- a/app/src/config/editor.ts +++ b/app/src/config/editor.ts @@ -343,9 +343,7 @@ export const editor = { } window.siyuan.config.editor = editorData; getAllModels().editor.forEach((item) => { - if (!changeReadonly) { - reloadProtyle(item.editor.protyle, false); - } + reloadProtyle(item.editor.protyle, false); let isFullWidth = item.editor.protyle.wysiwyg.element.getAttribute(Constants.CUSTOM_SY_FULLWIDTH); if (!isFullWidth) { isFullWidth = window.siyuan.config.editor.fullWidth ? "true" : "false"; diff --git a/app/src/mobile/util/MobileBackFoward.ts b/app/src/mobile/util/MobileBackFoward.ts index f5d2f1ada..3b3bcad98 100644 --- a/app/src/mobile/util/MobileBackFoward.ts +++ b/app/src/mobile/util/MobileBackFoward.ts @@ -6,7 +6,7 @@ import {zoomOut} from "../../menus/protyle"; import {processRender} from "../../protyle/util/processCode"; import {highlightRender} from "../../protyle/render/highlightRender"; import {blockRender} from "../../protyle/render/blockRender"; -import {disabledForeverProtyle, disabledProtyle, enableProtyle} from "../../protyle/util/onGet"; +import {disabledForeverProtyle, setReadonlyByConfig} from "../../protyle/util/onGet"; import {setStorageVal} from "../../protyle/util/compatibility"; import {closePanel} from "./closePanel"; import {showMessage} from "../../dialog/message"; @@ -92,18 +92,7 @@ const focusStack = (backStack: IBackStack) => { if (getResponse.data.isSyncing) { disabledForeverProtyle(protyle); } else { - let readOnly = window.siyuan.config.readonly ? "true" : "false"; - if (readOnly === "false") { - readOnly = window.siyuan.config.editor.readOnly ? "true" : "false"; - if (readOnly === "false") { - readOnly = protyle.wysiwyg.element.getAttribute(Constants.CUSTOM_SY_READONLY); - } - } - if (readOnly === "true") { - disabledProtyle(protyle); - } else { - enableProtyle(protyle); - } + setReadonlyByConfig(protyle); } protyle.contentElement.scrollTop = backStack.scrollTop; }); diff --git a/app/src/protyle/index.ts b/app/src/protyle/index.ts index 0fb2f45e6..df4d271a3 100644 --- a/app/src/protyle/index.ts +++ b/app/src/protyle/index.ts @@ -28,7 +28,7 @@ import {updatePanelByEditor} from "../editor/util"; import {setPanelFocus} from "../layout/util"; /// #endif import {Background} from "./header/Background"; -import {onGet} from "./util/onGet"; +import {onGet, setReadonlyByConfig} from "./util/onGet"; import {reloadProtyle} from "./util/reload"; import {renderBacklink} from "./wysiwyg/renderBacklink"; import {setEmpty} from "../mobile/util/setEmpty"; @@ -132,7 +132,7 @@ export class Protyle { break; case "readonly": window.siyuan.config.editor.readOnly = data.data; - reloadProtyle(this.protyle, false); + setReadonlyByConfig(this.protyle); break; case "heading2doc": case "li2doc": diff --git a/app/src/protyle/util/onGet.ts b/app/src/protyle/util/onGet.ts index da8cc6e9a..b8fc3eef0 100644 --- a/app/src/protyle/util/onGet.ts +++ b/app/src/protyle/util/onGet.ts @@ -240,18 +240,7 @@ const setHTML = (options: { protyle.breadcrumb.element.nextElementSibling.textContent = ""; } protyle.element.removeAttribute("disabled-forever"); - let readOnly = window.siyuan.config.readonly ? "true" : "false"; - if (readOnly === "false") { - readOnly = window.siyuan.config.editor.readOnly ? "true" : "false"; - if (readOnly === "false") { - readOnly = protyle.wysiwyg.element.getAttribute(Constants.CUSTOM_SY_READONLY); - } - } - if (readOnly === "true") { - disabledProtyle(protyle); - } else { - enableProtyle(protyle); - } + setReadonlyByConfig(protyle); } if (options.action.includes(Constants.CB_GET_SETID)) { // 点击大纲后,如果需要动态加载,在定位后,需要重置 block.id https://github.com/siyuan-note/siyuan/issues/4487 @@ -411,3 +400,18 @@ const focusElementById = (protyle: IProtyle, action: string[]) => { /// #endif } }; + +export const setReadonlyByConfig = (protyle: IProtyle) => { + let readOnly = window.siyuan.config.readonly ? "true" : "false"; + if (readOnly === "false") { + readOnly = window.siyuan.config.editor.readOnly ? "true" : "false"; + if (readOnly === "false") { + readOnly = protyle.wysiwyg.element.getAttribute(Constants.CUSTOM_SY_READONLY); + } + } + if (readOnly === "true") { + disabledProtyle(protyle); + } else { + enableProtyle(protyle); + } +}