From 5bdaa3d9fdccf238165f0dba81252f04dc946b3f Mon Sep 17 00:00:00 2001 From: Vanessa Date: Sat, 9 Jul 2022 15:53:52 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E6=94=AF=E6=8C=81=20ctrl+s=20https://g?= =?UTF-8?q?ithub.com/siyuan-note/siyuan/issues/5376?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/config/keymap.ts | 2 +- app/src/constants.ts | 2 +- app/src/protyle/wysiwyg/keydown.ts | 28 ++++++++++++++++++++++ app/src/util/globalShortcut.ts | 38 +++++++++++++++++++++++------- 4 files changed, 59 insertions(+), 11 deletions(-) diff --git a/app/src/config/keymap.ts b/app/src/config/keymap.ts index 3bc789369..4b5ad9c0d 100644 --- a/app/src/config/keymap.ts +++ b/app/src/config/keymap.ts @@ -268,7 +268,7 @@ export const keymap = { } if (["⌘", "⇧", "⌥", "⌃"].includes(keymapStr.substr(keymapStr.length - 1, 1)) || - ["⌘S", "⌘A", "⌘X", "⌘C", "⌘V", "⌘/", "⌘↑", "⌘↓", "⇧↑", "⇧↓", "⇧→", "⇧←", "⇧⇥", "⇧⌘⇥", "⌃⇥", "⌃⌘⇥", "⇧⌘→", "⇧⌘←", "⌘Home", "⌘End", "⇧↩", "↩", "PageUp", "PageDown", "⌫", "⌦"].includes(keymapStr)) { + ["⌘A", "⌘X", "⌘C", "⌘V", "⌘/", "⌘↑", "⌘↓", "⇧↑", "⇧↓", "⇧→", "⇧←", "⇧⇥", "⇧⌘⇥", "⌃⇥", "⌃⌘⇥", "⇧⌘→", "⇧⌘←", "⌘Home", "⌘End", "⇧↩", "↩", "PageUp", "PageDown", "⌫", "⌦"].includes(keymapStr)) { showMessage(tip + "] " + window.siyuan.languages.invalid); return; } diff --git a/app/src/constants.ts b/app/src/constants.ts index 18eda9625..7d9dbed0a 100644 --- a/app/src/constants.ts +++ b/app/src/constants.ts @@ -83,7 +83,7 @@ export abstract class Constants { }; // "⌘", "⇧", "⌥", "⌃" - // "⌘S", "⌘A", "⌘X", "⌘C", "⌘V", "⌘/", "⌘↑", "⌘↓", "⇧↑", "⇧↓", "⇧→", "⇧←", "⇧⇥", "⇧⌘⇥", "⌃⇥", "⌃⌘⇥", "⇧⌘→", "⇧⌘←", "⌘Home", "⌘End", "⇧↩", "↩", "PageUp", "PageDown", "⌫", "⌦" 不可自定义 + // "⌘A", "⌘X", "⌘C", "⌘V", "⌘/", "⌘↑", "⌘↓", "⇧↑", "⇧↓", "⇧→", "⇧←", "⇧⇥", "⇧⌘⇥", "⌃⇥", "⌃⌘⇥", "⇧⌘→", "⇧⌘←", "⌘Home", "⌘End", "⇧↩", "↩", "PageUp", "PageDown", "⌫", "⌦" 不可自定义 public static readonly SIYUAN_KEYMAP: IKeymap = { general: { syncNow: {default: "F9", custom: "F9"}, diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts index 94dc66d51..d2f6ff023 100644 --- a/app/src/protyle/wysiwyg/keydown.ts +++ b/app/src/protyle/wysiwyg/keydown.ts @@ -381,12 +381,14 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { topNodeElement = topNodeElement.parentElement; } zoomOut(protyle, topNodeElement.getAttribute("data-node-id")); + event.preventDefault(); event.stopPropagation(); return; } if (matchHotKey(window.siyuan.config.keymap.general.enterBack.custom, event)) { zoomOut(protyle, protyle.block.parent2ID, nodeElement.getAttribute("data-node-id")); + event.preventDefault(); event.stopPropagation(); return; } @@ -813,6 +815,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { } writeText(`siyuan://blocks/${actionElement.getAttribute("data-node-id")}`); event.preventDefault(); + event.stopPropagation(); return true; } /// #if !MOBILE @@ -837,6 +840,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { }); } event.preventDefault(); + event.stopPropagation(); return true; } if (matchHotKey(window.siyuan.config.keymap.editor.general.copyBlockEmbed.custom, event)) { @@ -849,6 +853,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { } writeText(`{{select * from blocks where id='${actionElement.getAttribute("data-node-id")}'}}`); event.preventDefault(); + event.stopPropagation(); return true; } @@ -876,6 +881,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { updateTransaction(protyle, topElement.getAttribute("data-node-id"), topElement.outerHTML, oldHTML); } event.preventDefault(); + event.stopPropagation(); return true; } if (matchHotKey(window.siyuan.config.keymap.editor.general.rename.custom, event)) { @@ -899,18 +905,21 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { }); } event.preventDefault(); + event.stopPropagation(); return; } if (selectText.trim() && matchHotKey(window.siyuan.config.keymap.editor.general.newNameFile.custom, event)) { newFileBySelect(selectText, protyle); event.preventDefault(); + event.stopPropagation(); return; } if (matchHotKey(window.siyuan.config.keymap.editor.general.newContentFile.custom, event)) { newFileContentBySelect(protyle); event.preventDefault(); + event.stopPropagation(); return; } if (matchHotKey(window.siyuan.config.keymap.editor.general.alignLeft.custom, event)) { @@ -987,31 +996,37 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { if (matchHotKey(window.siyuan.config.keymap.editor.heading.heading1.custom, event)) { phTransaction(protyle, range, nodeElement, 1); event.preventDefault(); + event.stopPropagation(); return true; } if (matchHotKey(window.siyuan.config.keymap.editor.heading.heading2.custom, event)) { phTransaction(protyle, range, nodeElement, 2); event.preventDefault(); + event.stopPropagation(); return true; } if (matchHotKey(window.siyuan.config.keymap.editor.heading.heading3.custom, event)) { phTransaction(protyle, range, nodeElement, 3); event.preventDefault(); + event.stopPropagation(); return true; } if (matchHotKey(window.siyuan.config.keymap.editor.heading.heading4.custom, event)) { phTransaction(protyle, range, nodeElement, 4); event.preventDefault(); + event.stopPropagation(); return true; } if (matchHotKey(window.siyuan.config.keymap.editor.heading.heading5.custom, event)) { phTransaction(protyle, range, nodeElement, 5); event.preventDefault(); + event.stopPropagation(); return true; } if (matchHotKey(window.siyuan.config.keymap.editor.heading.heading6.custom, event)) { phTransaction(protyle, range, nodeElement, 6); event.preventDefault(); + event.stopPropagation(); return true; } if (matchHotKey(window.siyuan.config.keymap.editor.insert.code.custom, event) && nodeElement.getAttribute("data-type") !== "NodeCodeBlock") { @@ -1025,6 +1040,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { updateTransaction(protyle, id, newHTML, html); highlightRender(newNodeElement); event.preventDefault(); + event.stopPropagation(); return true; } // toolbar action @@ -1064,10 +1080,12 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { if (selectElements.length > 0 && selectElements[0].getAttribute("data-type") === "NodeListItem") { listOutdent(protyle, Array.from(selectElements), range); event.preventDefault(); + event.stopPropagation(); return true; } else if (nodeElement.parentElement.classList.contains("li") && nodeElement.getAttribute("data-type") !== "NodeCodeBlock") { listOutdent(protyle, [nodeElement.parentElement], range); event.preventDefault(); + event.stopPropagation(); return true; } } @@ -1076,10 +1094,12 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { if (selectElements.length > 0 && selectElements[0].getAttribute("data-type") === "NodeListItem") { listIndent(protyle, Array.from(selectElements), range); event.preventDefault(); + event.stopPropagation(); return true; } else if (nodeElement.parentElement.classList.contains("li") && nodeElement.getAttribute("data-type") !== "NodeCodeBlock") { listIndent(protyle, [nodeElement.parentElement], range); event.preventDefault(); + event.stopPropagation(); return true; } } @@ -1088,6 +1108,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { protyle.hint.lastIndex = -1; protyle.hint.fill("* [ ] " + Lute.Caret, protyle); event.preventDefault(); + event.stopPropagation(); return; } @@ -1096,6 +1117,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { protyle.hint.lastIndex = -1; protyle.hint.fill(`| col1${Lute.Caret} | col2 | col3 |\n| --- | --- | --- |\n| | | |\n| | | |`, protyle); event.preventDefault(); + event.stopPropagation(); return; } @@ -1115,6 +1137,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { taskItemElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss")); updateTransaction(protyle, taskItemElement.getAttribute("data-node-id"), taskItemElement.outerHTML, html); event.preventDefault(); + event.stopPropagation(); return; } if (matchHotKey(window.siyuan.config.keymap.editor.general.insertBefore.custom, event)) { @@ -1125,6 +1148,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { if (matchHotKey(window.siyuan.config.keymap.editor.general.insertAfter.custom, event)) { insertEmptyBlock(protyle, "afterend"); event.preventDefault(); + event.stopPropagation(); return true; } @@ -1329,6 +1353,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { if (matchHotKey(window.siyuan.config.keymap.editor.general.vLayout.custom, event)) { event.preventDefault(); + event.stopPropagation(); const selectsElement: HTMLElement[] = Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select")); if (selectsElement.length < 2) { return; @@ -1343,6 +1368,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { if (matchHotKey(window.siyuan.config.keymap.editor.general.hLayout.custom, event)) { event.preventDefault(); + event.stopPropagation(); const selectsElement: HTMLElement[] = Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select")); if (selectsElement.length < 2) { return; @@ -1460,6 +1486,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { getCurrentWindow().webContents.pasteAndMatchStyle(); }, 100); event.preventDefault(); + event.stopPropagation(); return; } @@ -1470,6 +1497,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { if (isLocalPath(linkAddress)) { openBy(linkAddress, "folder"); event.preventDefault(); + event.stopPropagation(); } } return; diff --git a/app/src/util/globalShortcut.ts b/app/src/util/globalShortcut.ts index 847b707e0..e2f5d2b21 100644 --- a/app/src/util/globalShortcut.ts +++ b/app/src/util/globalShortcut.ts @@ -352,8 +352,9 @@ export const globalShortcut = () => { }); return; } - - if (event.key === window.siyuan.config.keymap.general.syncNow.custom) { + if (matchHotKey(window.siyuan.config.keymap.general.syncNow.custom, event)) { + event.preventDefault(); + event.stopPropagation(); if (needSubscribe() || document.querySelector("#barSync svg").classList.contains("fn__rotate")) { return; } @@ -362,7 +363,6 @@ export const globalShortcut = () => { return; } fetchPost("/api/sync/performSync", {}); - event.preventDefault(); return; } if (matchHotKey(window.siyuan.config.keymap.general.lockScreen.custom, event)) { @@ -372,23 +372,20 @@ export const globalShortcut = () => { }); }); event.preventDefault(); + event.stopPropagation(); return; } if (matchHotKey(window.siyuan.config.keymap.general.history.custom, event)) { openHistory(); event.preventDefault(); + event.stopPropagation(); return; } if (!window.siyuan.config.readonly && matchHotKey(window.siyuan.config.keymap.general.config.custom, event)) { openSetting(); - event.preventDefault(); - return; - } - // https://github.com/siyuan-note/insider/issues/445 - if (matchHotKey("⌘S", event)) { event.preventDefault(); event.stopPropagation(); - return true; + return; } const target = event.target as HTMLElement; if (matchHotKey("⌘A", event) && target.tagName !== "INPUT" && target.tagName !== "TEXTAREA") { @@ -404,6 +401,7 @@ export const globalShortcut = () => { target.blur(); } event.preventDefault(); + event.stopPropagation(); return true; } }); @@ -418,11 +416,13 @@ export const globalShortcut = () => { target.blur(); } event.preventDefault(); + event.stopPropagation(); return; } if (matchHotKey(window.siyuan.config.keymap.general.newFile.custom, event)) { newFile(undefined, undefined, true); event.preventDefault(); + event.stopPropagation(); return; } @@ -587,6 +587,7 @@ export const globalShortcut = () => { openGlobalSearch("", false); } event.preventDefault(); + event.stopPropagation(); return; } @@ -615,8 +616,16 @@ export const globalShortcut = () => { openSearch(searchKey); } event.preventDefault(); + event.stopPropagation(); return; } + + // https://github.com/siyuan-note/insider/issues/445 + if (matchHotKey("⌘S", event)) { + event.preventDefault(); + event.stopPropagation(); + return true; + } }); window.addEventListener("blur", () => { @@ -717,6 +726,7 @@ const editKeydown = (event: KeyboardEvent) => { openSearch(searchKey); } event.preventDefault(); + event.stopPropagation(); return true; } if (!isFileFocus && matchHotKey(window.siyuan.config.keymap.general.move.custom, event)) { @@ -732,6 +742,7 @@ const editKeydown = (event: KeyboardEvent) => { movePathTo(protyle.notebookId, protyle.path); } event.preventDefault(); + event.stopPropagation(); return true; } const target = event.target as HTMLElement; @@ -741,6 +752,7 @@ const editKeydown = (event: KeyboardEvent) => { if (matchHotKey(window.siyuan.config.keymap.editor.general.preview.custom, event)) { setEditMode(protyle, "preview"); event.preventDefault(); + event.stopPropagation(); return true; } if (matchHotKey(window.siyuan.config.keymap.editor.general.wysiwyg.custom, event)) { @@ -753,17 +765,20 @@ const editKeydown = (event: KeyboardEvent) => { onGet(getResponse, protyle); }); event.preventDefault(); + event.stopPropagation(); return true; } // 没有光标时,无法撤销 https://ld246.com/article/1624021111567 if (matchHotKey(window.siyuan.config.keymap.editor.general.undo.custom, event)) { protyle.undo.undo(protyle); event.preventDefault(); + event.stopPropagation(); return true; } if (matchHotKey(window.siyuan.config.keymap.editor.general.redo.custom, event)) { protyle.undo.redo(protyle); event.preventDefault(); + event.stopPropagation(); return true; } return false; @@ -777,6 +792,7 @@ const fileTreeKeydown = (event: KeyboardEvent) => { const files = dockFile.data.file as Files; if (matchHotKey(window.siyuan.config.keymap.general.selectOpen1.custom, event)) { event.preventDefault(); + event.stopPropagation(); const element = document.querySelector(".layout__wnd--active > .layout-tab-bar > .item--focus") || document.querySelector(".layout-tab-bar > .item--focus"); if (element) { @@ -815,6 +831,8 @@ const fileTreeKeydown = (event: KeyboardEvent) => { name: isFile ? getDisplayName(liElement.getAttribute("data-name"), false, true) : getNotebookName(notebookId), type: isFile ? "file" : "notebook", }); + event.preventDefault(); + event.stopPropagation(); return true; } if (matchHotKey("⌘/", event)) { @@ -832,6 +850,7 @@ const fileTreeKeydown = (event: KeyboardEvent) => { if (isFile && matchHotKey(window.siyuan.config.keymap.general.move.custom, event)) { movePathTo(notebookId, pathString, false); event.preventDefault(); + event.stopPropagation(); return true; } let searchKey = ""; @@ -847,6 +866,7 @@ const fileTreeKeydown = (event: KeyboardEvent) => { openSearch(searchKey, undefined, notebookId); } event.preventDefault(); + event.stopPropagation(); return true; } const target = event.target as HTMLElement;