From 3c2cd43d28dfc6f3df0efe49aa00178c6eb0809d Mon Sep 17 00:00:00 2001 From: ChasLui Date: Tue, 20 Dec 2022 19:47:35 +0800 Subject: [PATCH] fix: shortcuts should exclude the shift judgment (#796) * fix: Shortcuts should exclude the shift judgment * fix: eslint --- web/src/components/MemoEditor.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/web/src/components/MemoEditor.tsx b/web/src/components/MemoEditor.tsx index a1d0a5cf..12455cbd 100644 --- a/web/src/components/MemoEditor.tsx +++ b/web/src/components/MemoEditor.tsx @@ -102,7 +102,9 @@ const MemoEditor = () => { return; } - if (event.ctrlKey || event.metaKey) { + const isMetaKey = event.ctrlKey || event.metaKey; + const isShiftKey = event.shiftKey; + if (!isShiftKey && isMetaKey) { if (event.key === "Enter") { handleSaveBtnClick(); return; @@ -134,7 +136,7 @@ const MemoEditor = () => { } } - if (event.key === "Enter") { + if (!isShiftKey && event.key === "Enter") { const cursorPosition = editorRef.current.getCursorPosition(); const contentBeforeCursor = editorRef.current.getContent().slice(0, cursorPosition); const rowValue = last(contentBeforeCursor.split("\n")); @@ -169,13 +171,13 @@ const MemoEditor = () => { } return; } - if (event.key === "Escape") { + if (!isShiftKey && event.key === "Escape") { if (state.fullscreen) { handleFullscreenBtnClick(); } return; } - if (event.key === "Tab") { + if (!isShiftKey && event.key === "Tab") { event.preventDefault(); editorRef.current.insertText(" ".repeat(TAB_SPACE_WIDTH)); return;