Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

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

Vanessa932e45e61238
diff --git a/app/appearance/langs/en_US.json b/app/appearance/langs/en_US.json
index b9bd56dd04..3371f35bc1 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 f8cb7de45b..5de2065b77 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 4cec3578b1..372018432e 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 70828beea3..10869234f8 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 48423bdd63..c14382c506 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 76ba5c2475..e6f4ac4964 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 2075dacd43..b8915ff3dd 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 4f2218f29c..7e77e06fe2 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 881930572c..78ea8923a1 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;