From 8a543d45132d70f2cff613ecac1b85d27b4460a9 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Thu, 21 Aug 2025 13:00:05 +0300 Subject: [PATCH] chore(react/note_title): focus content on enter --- apps/client/src/widgets/note_title.bak | 3 --- apps/client/src/widgets/note_title.tsx | 12 ++++++++++-- apps/client/src/widgets/react/hooks.tsx | 3 ++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/apps/client/src/widgets/note_title.bak b/apps/client/src/widgets/note_title.bak index f1c0fc593..e79bd7517 100644 --- a/apps/client/src/widgets/note_title.bak +++ b/apps/client/src/widgets/note_title.bak @@ -31,9 +31,6 @@ export default class NoteTitleWidget extends NoteContextAwareWidget { } }); - shortcutService.bindElShortcut(this.$noteTitle, "return", () => { - this.triggerCommand("focusOnDetail", { ntxId: this.noteContext?.ntxId }); - }); } async beforeNoteSwitchEvent({ noteContext }: EventData<"beforeNoteSwitch">) { diff --git a/apps/client/src/widgets/note_title.tsx b/apps/client/src/widgets/note_title.tsx index 6f1f82e32..6f3581bbf 100644 --- a/apps/client/src/widgets/note_title.tsx +++ b/apps/client/src/widgets/note_title.tsx @@ -9,7 +9,7 @@ import { isLaunchBarConfig } from "../services/utils"; import appContext from "../components/app_context"; export default function NoteTitleWidget() { - const { note, noteId, componentId, viewScope, noteContext } = useNoteContext(); + const { note, noteId, componentId, viewScope, noteContext, parentComponent } = useNoteContext(); const title = useNoteProperty(note, "title", componentId); const isProtected = useNoteProperty(note, "isProtected"); const newTitle = useRef(""); @@ -41,7 +41,7 @@ export default function NoteTitleWidget() { }); useEffect(() => { - appContext.addBeforeUnloadListener(() => spacedUpdate.isAllSavedAndTriggerUpdate()); + appContext.addBeforeUnloadListener(() => spacedUpdate.isAllSavedAndTriggerUpdate()); }, []); return ( @@ -57,6 +57,14 @@ export default function NoteTitleWidget() { newTitle.current = newValue; spacedUpdate.scheduleUpdate(); }} + onKeyDown={(e) => { + // Focus on the note content when pressing enter. + if (e.key === "Enter") { + e.preventDefault(); + parentComponent.triggerCommand("focusOnDetail", { ntxId: noteContext?.ntxId }); + return; + } + }} />} ); diff --git a/apps/client/src/widgets/react/hooks.tsx b/apps/client/src/widgets/react/hooks.tsx index 56b5cb865..b08c4dac1 100644 --- a/apps/client/src/widgets/react/hooks.tsx +++ b/apps/client/src/widgets/react/hooks.tsx @@ -271,7 +271,8 @@ export function useNoteContext() { ntxId: noteContext?.ntxId, viewScope: noteContext?.viewScope, componentId: parentComponent.componentId, - noteContext: noteContext + noteContext, + parentComponent }; }