mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-23 18:10:12 +01:00
This commit is contained in:
parent
32939df926
commit
a644b10d9b
5 changed files with 16 additions and 44 deletions
|
|
@ -4,12 +4,11 @@ import {fetchPost} from "../util/fetch";
|
|||
import {confirmDialog} from "../dialog/confirmDialog";
|
||||
import {setPadding} from "../protyle/ui/initUI";
|
||||
import {reloadProtyle} from "../protyle/util/reload";
|
||||
import {disabledProtyle, enableProtyle} from "../protyle/util/onGet";
|
||||
import {updateHotkeyTip} from "../protyle/util/compatibility";
|
||||
|
||||
export const editor = {
|
||||
element: undefined as Element,
|
||||
setMode: (readOnly?: boolean) => {
|
||||
setReadonly: (readOnly?: boolean) => {
|
||||
const target = document.querySelector("#barReadonly");
|
||||
if (typeof readOnly === "undefined") {
|
||||
readOnly = target.getAttribute("aria-label") === `${window.siyuan.languages.use} ${window.siyuan.languages.editReadonly} ${updateHotkeyTip(window.siyuan.config.keymap.general.editMode.custom)}`;
|
||||
|
|
@ -24,41 +23,7 @@ export const editor = {
|
|||
target.setAttribute("aria-label", `${window.siyuan.languages.use} ${window.siyuan.languages.editReadonly} ${updateHotkeyTip(window.siyuan.config.keymap.general.editMode.custom)}`);
|
||||
target.querySelector("use").setAttribute("xlink:href", "#iconEdit");
|
||||
}
|
||||
fetchPost("/api/setting/setEditor", window.siyuan.config.editor, () => {
|
||||
const allModels = getAllModels();
|
||||
allModels.editor.forEach(editor => {
|
||||
if (readOnly) {
|
||||
disabledProtyle(editor.editor.protyle);
|
||||
} else {
|
||||
enableProtyle(editor.editor.protyle);
|
||||
}
|
||||
});
|
||||
allModels.backlink.forEach(backlink => {
|
||||
backlink.editors.forEach(editor => {
|
||||
if (readOnly) {
|
||||
disabledProtyle(editor.protyle);
|
||||
} else {
|
||||
enableProtyle(editor.protyle);
|
||||
}
|
||||
});
|
||||
});
|
||||
allModels.search.forEach(search => {
|
||||
if (readOnly) {
|
||||
disabledProtyle(search.edit.protyle);
|
||||
} else {
|
||||
enableProtyle(search.edit.protyle);
|
||||
}
|
||||
});
|
||||
window.siyuan.blockPanels.forEach(item => {
|
||||
item.editors.forEach(editor => {
|
||||
if (readOnly) {
|
||||
disabledProtyle(editor.protyle);
|
||||
} else {
|
||||
enableProtyle(editor.protyle);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
fetchPost("/api/setting/setEditor", window.siyuan.config.editor);
|
||||
},
|
||||
genHTML: () => {
|
||||
let fontFamilyHTML = "";
|
||||
|
|
@ -357,7 +322,7 @@ export const editor = {
|
|||
},
|
||||
onSetEditor: (editorData: IEditor) => {
|
||||
if (editorData.readOnly !== window.siyuan.config.editor.readOnly) {
|
||||
editor.setMode(editorData.readOnly);
|
||||
editor.setReadonly(editorData.readOnly);
|
||||
}
|
||||
window.siyuan.config.editor = editorData;
|
||||
getAllModels().editor.forEach((item) => {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import {updatePanelByEditor} from "../editor/util";
|
|||
import {setPanelFocus} from "../layout/util";
|
||||
/// #endif
|
||||
import {Background} from "./header/Background";
|
||||
import {onGet} from "./util/onGet";
|
||||
import {disabledProtyle, enableProtyle, onGet} from "./util/onGet";
|
||||
import {reloadProtyle} from "./util/reload";
|
||||
import {renderBacklink} from "./wysiwyg/renderBacklink";
|
||||
import {showKeyboardToolbar} from "../mobile/util/showKeyboardToolbar";
|
||||
|
|
@ -92,6 +92,13 @@ export class Protyle {
|
|||
onTransaction(this.protyle, item, false);
|
||||
});
|
||||
break;
|
||||
case "readonly":
|
||||
if (data.data) {
|
||||
enableProtyle(this.protyle);
|
||||
} else {
|
||||
disabledProtyle(this.protyle);
|
||||
}
|
||||
break;
|
||||
case "heading2doc":
|
||||
case "li2doc":
|
||||
if (this.protyle.block.rootID === data.data.srcRootBlockID) {
|
||||
|
|
|
|||
|
|
@ -576,7 +576,7 @@ export const globalShortcut = () => {
|
|||
}
|
||||
if (matchHotKey(window.siyuan.config.keymap.general.editMode.custom, event)) {
|
||||
event.preventDefault();
|
||||
editor.setMode();
|
||||
editor.setReadonly();
|
||||
return;
|
||||
}
|
||||
if (matchHotKey(window.siyuan.config.keymap.general.lockScreen.custom, event)) {
|
||||
|
|
|
|||
|
|
@ -231,7 +231,7 @@ export const initBar = () => {
|
|||
event.stopPropagation();
|
||||
break;
|
||||
} else if (target.id === "barReadonly") {
|
||||
editor.setMode();
|
||||
editor.setReadonly();
|
||||
event.stopPropagation();
|
||||
break;
|
||||
} else if (target.id === "barMode") {
|
||||
|
|
|
|||
|
|
@ -3,16 +3,16 @@ import {Tab} from "../layout/Tab";
|
|||
import {fetchPost} from "../util/fetch";
|
||||
import {isWindow} from "../util/functions";
|
||||
|
||||
const closeTab = (ipcData:IWebSocketData) => {
|
||||
const closeTab = (ipcData: IWebSocketData) => {
|
||||
const tab = getInstanceById(ipcData.data);
|
||||
if (tab && tab instanceof Tab) {
|
||||
tab.parent.removeTab(ipcData.data);
|
||||
}
|
||||
}
|
||||
export const onWindowsMsg = (ipcData:IWebSocketData) => {
|
||||
export const onWindowsMsg = (ipcData: IWebSocketData) => {
|
||||
switch (ipcData.cmd) {
|
||||
case "closetab":
|
||||
closeTab(ipcData)
|
||||
closeTab(ipcData);
|
||||
break;
|
||||
case "lockscreen":
|
||||
if (isWindow()) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue