diff --git a/app/appearance/langs/en_US.json b/app/appearance/langs/en_US.json index b9bd56dd0..3371f35bc 100644 --- a/app/appearance/langs/en_US.json +++ b/app/appearance/langs/en_US.json @@ -1,4 +1,5 @@ { + "switchReadonly": "Switch read-only mode", "original": "Original", "selectRelation": "Please select the related column first", "backRelation": "Bidirectional", diff --git a/app/appearance/langs/es_ES.json b/app/appearance/langs/es_ES.json index f8cb7de45..5de2065b7 100644 --- a/app/appearance/langs/es_ES.json +++ b/app/appearance/langs/es_ES.json @@ -1,4 +1,5 @@ { + "switchReadonly": "Cambiar modo de sólo lectura", "original": "Original", "selectRelation": "Seleccione primero la columna relacionada", "backRelation": "Bidireccional", diff --git a/app/appearance/langs/fr_FR.json b/app/appearance/langs/fr_FR.json index 4cec3578b..372018432 100644 --- a/app/appearance/langs/fr_FR.json +++ b/app/appearance/langs/fr_FR.json @@ -1,4 +1,5 @@ { + "switchReadonly": "Changer de mode lecture seule", "original": "Originale", "selectRelation": "Veuillez d'abord sélectionner la colonne associée", "backRelation": "Bidirectionnel", diff --git a/app/appearance/langs/zh_CHT.json b/app/appearance/langs/zh_CHT.json index 70828beea..10869234f 100644 --- a/app/appearance/langs/zh_CHT.json +++ b/app/appearance/langs/zh_CHT.json @@ -1,4 +1,5 @@ { + "switchReadonly": "唯讀模式切換", "original": "原值", "selectRelation": "請先選擇關聯列", "backRelation": "雙向關聯", diff --git a/app/appearance/langs/zh_CN.json b/app/appearance/langs/zh_CN.json index 48423bdd6..c14382c50 100644 --- a/app/appearance/langs/zh_CN.json +++ b/app/appearance/langs/zh_CN.json @@ -1,4 +1,5 @@ { + "switchReadonly": "只读模式切换", "original": "原值", "selectRelation": "请先选择关联列", "backRelation": "双向关联", diff --git a/app/src/boot/globalEvent/keydown.ts b/app/src/boot/globalEvent/keydown.ts index 76ba5c247..e6f4ac496 100644 --- a/app/src/boot/globalEvent/keydown.ts +++ b/app/src/boot/globalEvent/keydown.ts @@ -57,7 +57,7 @@ import {openCard, openCardByData} from "../../card/openCard"; import {lockScreen} from "../../dialog/processSystem"; import {isWindow} from "../../util/functions"; import {reloadProtyle} from "../../protyle/util/reload"; -import {fullscreen} from "../../protyle/breadcrumb/action"; +import {fullscreen, updateReadonly} from "../../protyle/breadcrumb/action"; import {openRecentDocs} from "../../business/openRecentDocs"; import {App} from "../../index"; import {commandPanel} from "../../plugin/commandPanel"; @@ -333,6 +333,11 @@ const editKeydown = (app: App, event: KeyboardEvent) => { zoomOut({protyle, id: protyle.block.rootID, focusId: protyle.block.id}); return true; } + if (matchHotKey(window.siyuan.config.keymap.editor.general.switchReadonly.custom, event)) { + event.preventDefault(); + updateReadonly(protyle.breadcrumb.element.parentElement.querySelector('.block__icon[data-type="readonly"]'), protyle); + return true; + } if (matchHotKey(window.siyuan.config.keymap.editor.general.backlinks.custom, event)) { event.preventDefault(); if (range) { diff --git a/app/src/constants.ts b/app/src/constants.ts index 2075dacd4..b8915ff3d 100644 --- a/app/src/constants.ts +++ b/app/src/constants.ts @@ -359,6 +359,7 @@ export abstract class Constants { refPopover: {default: "", custom: ""}, copyText: {default: "", custom: ""}, exitFocus: {default: "", custom: ""}, + switchReadonly: {default: "", custom: ""}, expand: {default: "⌘↓", custom: "⌘↓"}, collapse: {default: "⌘↑", custom: "⌘↑"}, insertBottom: {default: "⌥⌘.", custom: "⌥⌘."}, diff --git a/app/src/protyle/breadcrumb/action.ts b/app/src/protyle/breadcrumb/action.ts index 4f2218f29..7e77e06fe 100644 --- a/app/src/protyle/breadcrumb/action.ts +++ b/app/src/protyle/breadcrumb/action.ts @@ -8,6 +8,7 @@ import {hideAllElements, hideElements} from "../ui/hideElements"; import {hasClosestByClassName} from "../util/hasClosest"; import {reloadProtyle} from "../util/reload"; import {resize} from "../util/resize"; +import {disabledProtyle, enableProtyle} from "../util/onGet"; export const net2LocalAssets = (protyle: IProtyle, type: "Assets" | "Img") => { if (protyle.element.querySelector(".wysiwygLoading")) { @@ -81,3 +82,23 @@ export const fullscreen = (element: Element, btnElement?: Element) => { }); /// #endif }; + +export const updateReadonly = (target: Element, protyle: IProtyle) => { + 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" + } + }); + } + } +} diff --git a/app/src/protyle/breadcrumb/index.ts b/app/src/protyle/breadcrumb/index.ts index 881930572..78ea8923a 100644 --- a/app/src/protyle/breadcrumb/index.ts +++ b/app/src/protyle/breadcrumb/index.ts @@ -2,7 +2,7 @@ import {getIconByType} from "../../editor/getIcon"; import {fetchPost} from "../../util/fetch"; import {Constants} from "../../constants"; import {MenuItem} from "../../menus/Menu"; -import {fullscreen, net2LocalAssets} from "./action"; +import {fullscreen, net2LocalAssets, updateReadonly} from "./action"; import {openFileAttr} from "../../menus/commonMenuItem"; import {setEditMode} from "../util/setEditMode"; import {RecordMedia} from "../util/RecordMedia"; @@ -107,23 +107,7 @@ export class Breadcrumb { event.preventDefault(); break; } else if (type === "readonly") { - 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" - } - }); - } - } + updateReadonly(target, protyle); event.stopPropagation(); event.preventDefault(); break;