瀏覽代碼

:art: fix https://github.com/siyuan-note/siyuan/issues/10163

Vanessa 1 年之前
父節點
當前提交
932e45e612

+ 1 - 0
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",

+ 1 - 0
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",

+ 1 - 0
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",

+ 1 - 0
app/appearance/langs/zh_CHT.json

@@ -1,4 +1,5 @@
 {
+  "switchReadonly": "唯讀模式切換",
   "original": "原值",
   "selectRelation": "請先選擇關聯列",
   "backRelation": "雙向關聯",

+ 1 - 0
app/appearance/langs/zh_CN.json

@@ -1,4 +1,5 @@
 {
+  "switchReadonly": "只读模式切换",
   "original": "原值",
   "selectRelation": "请先选择关联列",
   "backRelation": "双向关联",

+ 6 - 1
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) {

+ 1 - 0
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: "⌥⌘."},

+ 21 - 0
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"
+                }
+            });
+        }
+    }
+}

+ 2 - 18
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;