Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.
Go dockerfossgomarkdownmemomicroblognote-takingnotesopen-sourceown-your-datareactself-hostedsqlitetimeline
fix(memo-editor): scope Cmd+Enter save to the active editor (#5745)
memoclaw05810e7882cb
diff --git a/web/src/components/MemoEditor/hooks/useKeyboard.ts b/web/src/components/MemoEditor/hooks/useKeyboard.tsindex e90537503..880806370 100644--- a/web/src/components/MemoEditor/hooks/useKeyboard.ts+++ b/web/src/components/MemoEditor/hooks/useKeyboard.ts@@ -5,16 +5,29 @@ interface UseKeyboardOptions {onSave: () => void;}-export const useKeyboard = (_editorRef: React.RefObject<EditorRefActions | null>, options: UseKeyboardOptions) => {+export const useKeyboard = (editorRef: React.RefObject<EditorRefActions | null>, options: UseKeyboardOptions) => {useEffect(() => {const handleKeyDown = (event: KeyboardEvent) => {- if ((event.metaKey || event.ctrlKey) && event.key === "Enter") {- event.preventDefault();- options.onSave();+ if (!(event.metaKey || event.ctrlKey) || event.key !== "Enter") {+ return;}++ const editor = editorRef.current?.getEditor();+ if (!editor) {+ return;+ }++ const activeElement = document.activeElement;+ const target = event.target;+ if (activeElement !== editor && target !== editor) {+ return;+ }++ event.preventDefault();+ options.onSave();};window.addEventListener("keydown", handleKeyDown);return () => window.removeEventListener("keydown", handleKeyDown);- }, [options]);+ }, [editorRef, options]);};