This commit is contained in:
Vanessa 2024-05-13 17:06:28 +08:00
parent f15b2f8666
commit b2b1089e3d
7 changed files with 27 additions and 22 deletions

View file

@ -129,18 +129,18 @@ export const globalCommand = (command: string, app: App) => {
let newItem: Tab; let newItem: Tab;
if (command === "goToEditTabPrev") { if (command === "goToEditTabPrev") {
if (index === 0) { if (index === 0) {
newItem = tabs[tabs.length - 1] newItem = tabs[tabs.length - 1];
} else { } else {
newItem = tabs[index - 1] newItem = tabs[index - 1];
} }
} else { } else {
if (index === tabs.length - 1) { if (index === tabs.length - 1) {
newItem = tabs[0] newItem = tabs[0];
} else { } else {
newItem = tabs[index + 1] newItem = tabs[index + 1];
} }
} }
const tab = getInstanceById(newItem.id) as Tab const tab = getInstanceById(newItem.id) as Tab;
tab.parent.switchTab(newItem.headElement); tab.parent.switchTab(newItem.headElement);
tab.parent.showHeading(); tab.parent.showHeading();
} }
@ -229,9 +229,9 @@ export const globalCommand = (command: string, app: App) => {
openHistory(app); openHistory(app);
return true; return true;
case "editReadonly": case "editReadonly":
setReadOnly(!window.siyuan.config.editor.readOnly) setReadOnly(!window.siyuan.config.editor.readOnly);
return true; return true;
} }
return false return false;
} };

View file

@ -25,4 +25,4 @@ export const onluProtyleCommand = (options: {
return true; return true;
} }
return false; return false;
} };

View file

@ -43,7 +43,6 @@ import {escapeHtml} from "../../util/escape";
import {syncGuide} from "../../sync/syncGuide"; import {syncGuide} from "../../sync/syncGuide";
import {getStartEndElement, goEnd, goHome} from "../../protyle/wysiwyg/commonHotkey"; import {getStartEndElement, goEnd, goHome} from "../../protyle/wysiwyg/commonHotkey";
import {getNextFileLi, getPreviousFileLi} from "../../protyle/wysiwyg/getBlock"; import {getNextFileLi, getPreviousFileLi} from "../../protyle/wysiwyg/getBlock";
import {editor} from "../../config/editor";
import {hintMoveBlock} from "../../protyle/hint/extend"; import {hintMoveBlock} from "../../protyle/hint/extend";
import {Backlink} from "../../layout/dock/Backlink"; import {Backlink} from "../../layout/dock/Backlink";
/// #if !BROWSER /// #if !BROWSER
@ -1267,7 +1266,7 @@ export const windowKeyDown = (app: App, event: KeyboardEvent) => {
} }
if (matchHotKey(window.siyuan.config.keymap.general.editReadonly.custom, event)) { if (matchHotKey(window.siyuan.config.keymap.general.editReadonly.custom, event)) {
event.preventDefault(); event.preventDefault();
setReadOnly(!window.siyuan.config.editor.readOnly) setReadOnly(!window.siyuan.config.editor.readOnly);
return; return;
} }
if (matchHotKey(window.siyuan.config.keymap.general.lockScreen.custom, event)) { if (matchHotKey(window.siyuan.config.keymap.general.lockScreen.custom, event)) {

View file

@ -0,0 +1,6 @@
import {fetchPost} from "../../util/fetch";
export const setReadOnly = (readOnly: boolean) => {
window.siyuan.config.editor.readOnly = readOnly;
fetchPost("/api/setting/setEditor", window.siyuan.config.editor);
};

View file

@ -11,7 +11,7 @@ export const textMenu = (target: Element) => {
click() { click() {
document.execCommand("copy"); document.execCommand("copy");
} }
}) });
menu.addItem({ menu.addItem({
label: window.siyuan.languages.selectAll, label: window.siyuan.languages.selectAll,
icon: "iconSelect", icon: "iconSelect",
@ -19,8 +19,8 @@ export const textMenu = (target: Element) => {
if (getSelection().rangeCount === 0) { if (getSelection().rangeCount === 0) {
return; return;
} }
getSelection().getRangeAt(0).selectNode(target) getSelection().getRangeAt(0).selectNode(target);
}
})
return menu
} }
});
return menu;
};

View file

@ -49,7 +49,7 @@ import {
getStartEndElement, getStartEndElement,
upSelect upSelect
} from "./commonHotkey"; } from "./commonHotkey";
import {fileAnnotationRefMenu, linkMenu, refMenu, setFold, tagMenu, zoomOut} from "../../menus/protyle"; import {fileAnnotationRefMenu, linkMenu, refMenu, setFold, tagMenu} from "../../menus/protyle";
import {openAttr} from "../../menus/commonMenuItem"; import {openAttr} from "../../menus/commonMenuItem";
import {Constants} from "../../constants"; import {Constants} from "../../constants";
import {fetchPost} from "../../util/fetch"; import {fetchPost} from "../../util/fetch";
@ -473,7 +473,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
protyle, protyle,
command: "enter", command: "enter",
previousRange: range, previousRange: range,
}) });
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
return; return;
@ -484,7 +484,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
protyle, protyle,
command: "enterBack", command: "enterBack",
previousRange: range, previousRange: range,
}) });
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
return; return;

View file

@ -98,7 +98,7 @@ export const newFile = (optios: {
} }
if ((data.data.path.indexOf("/") > -1 && optios.useSavePath) || optios.name) { if ((data.data.path.indexOf("/") > -1 && optios.useSavePath) || optios.name) {
if (data.data.path.startsWith("/") || optios.currentPath === "/") { if (data.data.path.startsWith("/") || optios.currentPath === "/") {
const createPath = pathPosix().join(data.data.path, optios.name || (data.data.path.endsWith("/") ? window.siyuan.languages.untitled : "")) const createPath = pathPosix().join(data.data.path, optios.name || (data.data.path.endsWith("/") ? window.siyuan.languages.untitled : ""));
fetchPost("/api/filetree/createDocWithMd", { fetchPost("/api/filetree/createDocWithMd", {
notebook: data.data.box, notebook: data.data.box,
path: createPath, path: createPath,
@ -123,7 +123,7 @@ export const newFile = (optios: {
notebook: data.data.box, notebook: data.data.box,
path: optios.notebookId === data.data.box ? (optios.currentPath.endsWith(".sy") ? optios.currentPath : optios.currentPath + ".sy") : (data.data.path || "/") path: optios.notebookId === data.data.box ? (optios.currentPath.endsWith(".sy") ? optios.currentPath : optios.currentPath + ".sy") : (data.data.path || "/")
}, (responseHPath) => { }, (responseHPath) => {
const createPath = pathPosix().join(responseHPath.data, data.data.path, optios.name || (data.data.path.endsWith("/") ? window.siyuan.languages.untitled : "")) const createPath = pathPosix().join(responseHPath.data, data.data.path, optios.name || (data.data.path.endsWith("/") ? window.siyuan.languages.untitled : ""));
fetchPost("/api/filetree/createDocWithMd", { fetchPost("/api/filetree/createDocWithMd", {
notebook: data.data.box, notebook: data.data.box,
path: createPath, path: createPath,
@ -151,7 +151,7 @@ export const newFile = (optios: {
return; return;
} }
if (optios.notebookId !== data.data.box) { if (optios.notebookId !== data.data.box) {
const createPath = pathPosix().join(data.data.path || "/", optios.name || (data.data.path.endsWith("/") ? window.siyuan.languages.untitled : "")) const createPath = pathPosix().join(data.data.path || "/", optios.name || (data.data.path.endsWith("/") ? window.siyuan.languages.untitled : ""));
fetchPost("/api/filetree/createDocWithMd", { fetchPost("/api/filetree/createDocWithMd", {
notebook: data.data.box, notebook: data.data.box,
path: createPath, path: createPath,