diff --git a/app/appearance/langs/zh_CN.json b/app/appearance/langs/zh_CN.json index 407691c90..10b645f60 100644 --- a/app/appearance/langs/zh_CN.json +++ b/app/appearance/langs/zh_CN.json @@ -1,4 +1,6 @@ { + "tempUnlock": "临时解锁", + "cancelTempUnlock": "取消临时解锁", "addFilter": "添加筛选条件", "removeFilters": "清空筛选规则", "checked": "已完成", diff --git a/app/src/config/editor.ts b/app/src/config/editor.ts index 3dcd6244f..f32cea7d9 100644 --- a/app/src/config/editor.ts +++ b/app/src/config/editor.ts @@ -316,7 +316,7 @@ export const editor = { fontFamily: fontFamilyElement.value, emoji: window.siyuan.config.editor.emoji }, response => { - editor.onSetEditor(response.data); + editor._onSetEditor(response.data); }); }; editor.element.querySelectorAll("input.b3-switch, select.b3-select, input.b3-slider").forEach((item) => { @@ -336,13 +336,16 @@ export const editor = { }); }); }, - onSetEditor: (editorData: IEditor) => { - if (editorData.readOnly !== window.siyuan.config.editor.readOnly) { + _onSetEditor: (editorData: IEditor) => { + const changeReadonly = editorData.readOnly !== window.siyuan.config.editor.readOnly + if (changeReadonly) { editor.setReadonly(editorData.readOnly); } window.siyuan.config.editor = editorData; getAllModels().editor.forEach((item) => { - reloadProtyle(item.editor.protyle, false); + if (!changeReadonly) { + 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 b5768d875..f5d2f1ada 100644 --- a/app/src/mobile/util/MobileBackFoward.ts +++ b/app/src/mobile/util/MobileBackFoward.ts @@ -94,9 +94,9 @@ const focusStack = (backStack: IBackStack) => { } else { let readOnly = window.siyuan.config.readonly ? "true" : "false"; if (readOnly === "false") { - readOnly = protyle.wysiwyg.element.getAttribute(Constants.CUSTOM_SY_READONLY); - if (!readOnly) { - readOnly = window.siyuan.config.editor.readOnly ? "true" : "false"; + readOnly = window.siyuan.config.editor.readOnly ? "true" : "false"; + if (readOnly === "false") { + readOnly = protyle.wysiwyg.element.getAttribute(Constants.CUSTOM_SY_READONLY); } } if (readOnly === "true") { diff --git a/app/src/protyle/breadcrumb/index.ts b/app/src/protyle/breadcrumb/index.ts index a1a080683..70f800c42 100644 --- a/app/src/protyle/breadcrumb/index.ts +++ b/app/src/protyle/breadcrumb/index.ts @@ -20,7 +20,7 @@ import {setPanelFocus} from "../../layout/util"; /// #if !BROWSER import {ipcRenderer} from "electron"; /// #endif -import {onGet} from "../util/onGet"; +import {disabledProtyle, enableProtyle, onGet} from "../util/onGet"; import {hideElements} from "../ui/hideElements"; import {confirmDialog} from "../../dialog/confirmDialog"; import {reloadProtyle} from "../util/reload"; @@ -45,8 +45,8 @@ export class Breadcrumb { '
'} - - + + @@ -107,10 +107,23 @@ export class Breadcrumb { event.preventDefault(); break; } else if (type === "readonly") { - fetchPost("/api/attr/setBlockAttrs", { - id: protyle.block.rootID, - attrs: {[Constants.CUSTOM_SY_READONLY]: target.querySelector("use").getAttribute("xlink:href") === "#iconUnlock" ? "true" : "false"} - }); + if (!window.siyuan.config.readonly) { + const isReadonly = target.querySelector("use").getAttribute("xlink:href") !== "#iconUnlock" + if (window.siyuan.config.editor.readOnly) { + if (isReadonly) { + enableProtyle(protyle); + } else { + disabledProtyle(protyle); + } + } else { + fetchPost("/api/attr/setBlockAttrs", { + id: protyle.block.rootID, + attrs: { + [Constants.CUSTOM_SY_READONLY]: isReadonly ? "false" : "true" + } + }); + } + } event.stopPropagation(); event.preventDefault(); break; @@ -426,43 +439,45 @@ export class Breadcrumb { type: "submenu", submenu: editSubmenu }).element); - const isCustomReadonly = protyle.wysiwyg.element.getAttribute(Constants.CUSTOM_SY_READONLY); - window.siyuan.menus.menu.append(new MenuItem({ - label: window.siyuan.languages.editReadonly, - icon: "iconLock", - type: "submenu", - submenu: [{ - iconHTML: "", - current: isCustomReadonly === "true", - label: window.siyuan.languages.enable, - click() { - fetchPost("/api/attr/setBlockAttrs", { - id: protyle.block.rootID, - attrs: {[Constants.CUSTOM_SY_READONLY]: "true"} - }); - } - }, { - iconHTML: "", - current: isCustomReadonly === "false", - label: window.siyuan.languages.disable, - click() { - fetchPost("/api/attr/setBlockAttrs", { - id: protyle.block.rootID, - attrs: {[Constants.CUSTOM_SY_READONLY]: "false"} - }); - } - }, { - iconHTML: "", - current: !isCustomReadonly, - label: window.siyuan.languages.default, - click() { - fetchPost("/api/attr/setBlockAttrs", { - id: protyle.block.rootID, - attrs: {[Constants.CUSTOM_SY_READONLY]: ""} - }); - } - }] - }).element); + if (!window.siyuan.config.editor.readOnly && !window.siyuan.config.readonly) { + const isCustomReadonly = protyle.wysiwyg.element.getAttribute(Constants.CUSTOM_SY_READONLY); + window.siyuan.menus.menu.append(new MenuItem({ + label: window.siyuan.languages.editReadonly, + icon: "iconLock", + type: "submenu", + submenu: [{ + iconHTML: "", + current: isCustomReadonly === "true", + label: window.siyuan.languages.enable, + click() { + fetchPost("/api/attr/setBlockAttrs", { + id: protyle.block.rootID, + attrs: {[Constants.CUSTOM_SY_READONLY]: "true"} + }); + } + }, { + iconHTML: "", + current: isCustomReadonly === "false", + label: window.siyuan.languages.disable, + click() { + fetchPost("/api/attr/setBlockAttrs", { + id: protyle.block.rootID, + attrs: {[Constants.CUSTOM_SY_READONLY]: "false"} + }); + } + }, { + iconHTML: "", + current: !isCustomReadonly, + label: window.siyuan.languages.default, + click() { + fetchPost("/api/attr/setBlockAttrs", { + id: protyle.block.rootID, + attrs: {[Constants.CUSTOM_SY_READONLY]: ""} + }); + } + }] + }).element); + } /// #if !MOBILE if (!protyle.disabled) { const isCustomFullWidth = protyle.wysiwyg.element.getAttribute(Constants.CUSTOM_SY_FULLWIDTH); diff --git a/app/src/protyle/index.ts b/app/src/protyle/index.ts index 113504cd8..bd234f588 100644 --- a/app/src/protyle/index.ts +++ b/app/src/protyle/index.ts @@ -123,13 +123,8 @@ export class Protyle { }); break; case "readonly": - if (!this.protyle.wysiwyg.element.getAttribute(Constants.CUSTOM_SY_READONLY)) { - if (data.data) { - disabledProtyle(this.protyle); - } else { - enableProtyle(this.protyle); - } - } + window.siyuan.config.editor.readOnly = data.data; + reloadProtyle(this.protyle, false); break; case "heading2doc": case "li2doc": @@ -392,7 +387,7 @@ export class Protyle { insertHTML(html, this.protyle, isBlock, useProtyleRange); } - public transaction( doOperations: IOperation[], undoOperations?: IOperation[]) { - transaction(this.protyle, doOperations, undoOperations); + public transaction(doOperations: IOperation[], undoOperations?: IOperation[]) { + transaction(this.protyle, doOperations, undoOperations); } } diff --git a/app/src/protyle/util/onGet.ts b/app/src/protyle/util/onGet.ts index 270af7ba7..e7a34d5b8 100644 --- a/app/src/protyle/util/onGet.ts +++ b/app/src/protyle/util/onGet.ts @@ -242,9 +242,9 @@ const setHTML = (options: { protyle.element.removeAttribute("disabled-forever"); let readOnly = window.siyuan.config.readonly ? "true" : "false"; if (readOnly === "false") { - readOnly = protyle.wysiwyg.element.getAttribute(Constants.CUSTOM_SY_READONLY); - if (!readOnly) { - readOnly = window.siyuan.config.editor.readOnly ? "true" : "false"; + readOnly = window.siyuan.config.editor.readOnly ? "true" : "false"; + if (readOnly === "false") { + readOnly = protyle.wysiwyg.element.getAttribute(Constants.CUSTOM_SY_READONLY); } } if (readOnly === "true") { @@ -339,7 +339,7 @@ export const disabledProtyle = (protyle: IProtyle) => { }); if (protyle.breadcrumb) { protyle.breadcrumb.element.parentElement.querySelector('[data-type="readonly"] use').setAttribute("xlink:href", "#iconLock"); - protyle.breadcrumb.element.parentElement.querySelector('[data-type="readonly"]').setAttribute("aria-label", window.siyuan.languages.unlockEdit); + protyle.breadcrumb.element.parentElement.querySelector('[data-type="readonly"]').setAttribute("aria-label", window.siyuan.config.editor.readOnly ? window.siyuan.languages.tempUnlock : window.siyuan.languages.unlockEdit); } hideTooltip(); }; @@ -373,7 +373,7 @@ export const enableProtyle = (protyle: IProtyle) => { }); if (protyle.breadcrumb) { protyle.breadcrumb.element.parentElement.querySelector('[data-type="readonly"] use').setAttribute("xlink:href", "#iconUnlock"); - protyle.breadcrumb.element.parentElement.querySelector('[data-type="readonly"]').setAttribute("aria-label", window.siyuan.languages.lockEdit); + protyle.breadcrumb.element.parentElement.querySelector('[data-type="readonly"]').setAttribute("aria-label", window.siyuan.config.editor.readOnly ? window.siyuan.languages.cancelTempUnlock : window.siyuan.languages.lockEdit); } hideTooltip(); };