mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-24 02:20:13 +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 {confirmDialog} from "../dialog/confirmDialog";
|
||||||
import {setPadding} from "../protyle/ui/initUI";
|
import {setPadding} from "../protyle/ui/initUI";
|
||||||
import {reloadProtyle} from "../protyle/util/reload";
|
import {reloadProtyle} from "../protyle/util/reload";
|
||||||
import {disabledProtyle, enableProtyle} from "../protyle/util/onGet";
|
|
||||||
import {updateHotkeyTip} from "../protyle/util/compatibility";
|
import {updateHotkeyTip} from "../protyle/util/compatibility";
|
||||||
|
|
||||||
export const editor = {
|
export const editor = {
|
||||||
element: undefined as Element,
|
element: undefined as Element,
|
||||||
setMode: (readOnly?: boolean) => {
|
setReadonly: (readOnly?: boolean) => {
|
||||||
const target = document.querySelector("#barReadonly");
|
const target = document.querySelector("#barReadonly");
|
||||||
if (typeof readOnly === "undefined") {
|
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)}`;
|
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.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");
|
target.querySelector("use").setAttribute("xlink:href", "#iconEdit");
|
||||||
}
|
}
|
||||||
fetchPost("/api/setting/setEditor", window.siyuan.config.editor, () => {
|
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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
genHTML: () => {
|
genHTML: () => {
|
||||||
let fontFamilyHTML = "";
|
let fontFamilyHTML = "";
|
||||||
|
|
@ -357,7 +322,7 @@ export const editor = {
|
||||||
},
|
},
|
||||||
onSetEditor: (editorData: IEditor) => {
|
onSetEditor: (editorData: IEditor) => {
|
||||||
if (editorData.readOnly !== window.siyuan.config.editor.readOnly) {
|
if (editorData.readOnly !== window.siyuan.config.editor.readOnly) {
|
||||||
editor.setMode(editorData.readOnly);
|
editor.setReadonly(editorData.readOnly);
|
||||||
}
|
}
|
||||||
window.siyuan.config.editor = editorData;
|
window.siyuan.config.editor = editorData;
|
||||||
getAllModels().editor.forEach((item) => {
|
getAllModels().editor.forEach((item) => {
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ import {updatePanelByEditor} from "../editor/util";
|
||||||
import {setPanelFocus} from "../layout/util";
|
import {setPanelFocus} from "../layout/util";
|
||||||
/// #endif
|
/// #endif
|
||||||
import {Background} from "./header/Background";
|
import {Background} from "./header/Background";
|
||||||
import {onGet} from "./util/onGet";
|
import {disabledProtyle, enableProtyle, onGet} from "./util/onGet";
|
||||||
import {reloadProtyle} from "./util/reload";
|
import {reloadProtyle} from "./util/reload";
|
||||||
import {renderBacklink} from "./wysiwyg/renderBacklink";
|
import {renderBacklink} from "./wysiwyg/renderBacklink";
|
||||||
import {showKeyboardToolbar} from "../mobile/util/showKeyboardToolbar";
|
import {showKeyboardToolbar} from "../mobile/util/showKeyboardToolbar";
|
||||||
|
|
@ -92,6 +92,13 @@ export class Protyle {
|
||||||
onTransaction(this.protyle, item, false);
|
onTransaction(this.protyle, item, false);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "readonly":
|
||||||
|
if (data.data) {
|
||||||
|
enableProtyle(this.protyle);
|
||||||
|
} else {
|
||||||
|
disabledProtyle(this.protyle);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case "heading2doc":
|
case "heading2doc":
|
||||||
case "li2doc":
|
case "li2doc":
|
||||||
if (this.protyle.block.rootID === data.data.srcRootBlockID) {
|
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)) {
|
if (matchHotKey(window.siyuan.config.keymap.general.editMode.custom, event)) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
editor.setMode();
|
editor.setReadonly();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (matchHotKey(window.siyuan.config.keymap.general.lockScreen.custom, event)) {
|
if (matchHotKey(window.siyuan.config.keymap.general.lockScreen.custom, event)) {
|
||||||
|
|
|
||||||
|
|
@ -231,7 +231,7 @@ export const initBar = () => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
break;
|
break;
|
||||||
} else if (target.id === "barReadonly") {
|
} else if (target.id === "barReadonly") {
|
||||||
editor.setMode();
|
editor.setReadonly();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
break;
|
break;
|
||||||
} else if (target.id === "barMode") {
|
} else if (target.id === "barMode") {
|
||||||
|
|
|
||||||
|
|
@ -3,16 +3,16 @@ import {Tab} from "../layout/Tab";
|
||||||
import {fetchPost} from "../util/fetch";
|
import {fetchPost} from "../util/fetch";
|
||||||
import {isWindow} from "../util/functions";
|
import {isWindow} from "../util/functions";
|
||||||
|
|
||||||
const closeTab = (ipcData:IWebSocketData) => {
|
const closeTab = (ipcData: IWebSocketData) => {
|
||||||
const tab = getInstanceById(ipcData.data);
|
const tab = getInstanceById(ipcData.data);
|
||||||
if (tab && tab instanceof Tab) {
|
if (tab && tab instanceof Tab) {
|
||||||
tab.parent.removeTab(ipcData.data);
|
tab.parent.removeTab(ipcData.data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export const onWindowsMsg = (ipcData:IWebSocketData) => {
|
export const onWindowsMsg = (ipcData: IWebSocketData) => {
|
||||||
switch (ipcData.cmd) {
|
switch (ipcData.cmd) {
|
||||||
case "closetab":
|
case "closetab":
|
||||||
closeTab(ipcData)
|
closeTab(ipcData);
|
||||||
break;
|
break;
|
||||||
case "lockscreen":
|
case "lockscreen":
|
||||||
if (isWindow()) {
|
if (isWindow()) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue