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/9598

Vanessa320110d57eaa
diff --git a/app/appearance/langs/zh_CN.json b/app/appearance/langs/zh_CN.json
index 407691c901..10b645f606 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 3dcd6244f9..f32cea7d94 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 b5768d8753..f5d2f1ada0 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 a1a080683d..70f800c420 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 {
'<div class="protyle-breadcrumb__bar"></div>'}
<span class="protyle-breadcrumb__space"></span>
<button class="protyle-breadcrumb__icon fn__none" data-type="exit-focus">${window.siyuan.languages.exitFocus}</button>
-<button class="block__icon block__icon--show fn__flex-center ariaLabel" aria-label="${window.siyuan.languages.lockEdit}" data-type="readonly"><svg><use xlink:href="#iconUnlock"></use></svg></button>
-<span class="fn__space"></span>
+<button class="block__icon block__icon--show fn__flex-center ariaLabel${window.siyuan.config.readonly ? " fn__none" : ""}" aria-label="${window.siyuan.languages.lockEdit}" data-type="readonly"><svg><use xlink:href="#iconUnlock"></use></svg></button>
+<span class="fn__space${window.siyuan.config.readonly ? " fn__none" : ""}"></span>
<button class="block__icon block__icon--show fn__flex-center ariaLabel" data-type="doc" aria-label="${isMac() ? window.siyuan.languages.gutterTip2 : window.siyuan.languages.gutterTip2.replace("⇧", "Shift+")}"><svg><use xlink:href="#iconFile"></use></svg></button>
<span class="fn__space"></span>
<button class="block__icon block__icon--show fn__flex-center ariaLabel" data-type="more" aria-label="${window.siyuan.languages.more}"><svg><use xlink:href="#iconMore"></use></svg></button>
@@ -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 113504cd86..bd234f5886 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 270af7ba7e..e7a34d5b87 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();
};