From 3f105f7b8b5182b1c4ba2ef47d516c236cfdf154 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 24 Aug 2025 16:45:17 +0300 Subject: [PATCH] chore(react/ribbon): focus on search textbox --- apps/client/src/components/app_context.ts | 1 - .../src/components/root_command_executor.ts | 2 -- .../src/widgets/ribbon/SearchDefinitionTab.tsx | 3 +++ .../widgets/search_options/search_string.ts | 18 ------------------ 4 files changed, 3 insertions(+), 21 deletions(-) delete mode 100644 apps/client/src/widgets/search_options/search_string.ts diff --git a/apps/client/src/components/app_context.ts b/apps/client/src/components/app_context.ts index 35b8b8585..319988aa4 100644 --- a/apps/client/src/components/app_context.ts +++ b/apps/client/src/components/app_context.ts @@ -85,7 +85,6 @@ export type CommandMappings = { focusTree: CommandData; focusOnTitle: CommandData; focusOnDetail: CommandData; - focusOnSearchDefinition: Required; searchNotes: CommandData & { searchString?: string; ancestorNoteId?: string | null; diff --git a/apps/client/src/components/root_command_executor.ts b/apps/client/src/components/root_command_executor.ts index 8e7df9494..632eb0a88 100644 --- a/apps/client/src/components/root_command_executor.ts +++ b/apps/client/src/components/root_command_executor.ts @@ -43,8 +43,6 @@ export default class RootCommandExecutor extends Component { const noteContext = await appContext.tabManager.openTabWithNoteWithHoisting(searchNote.noteId, { activate: true }); - - appContext.triggerCommand("focusOnSearchDefinition", { ntxId: noteContext.ntxId }); } async searchInSubtreeCommand({ notePath }: CommandListenerData<"searchInSubtree">) { diff --git a/apps/client/src/widgets/ribbon/SearchDefinitionTab.tsx b/apps/client/src/widgets/ribbon/SearchDefinitionTab.tsx index 2f202fe12..94de4f6fd 100644 --- a/apps/client/src/widgets/ribbon/SearchDefinitionTab.tsx +++ b/apps/client/src/widgets/ribbon/SearchDefinitionTab.tsx @@ -254,6 +254,9 @@ function SearchStringOption({ note, refreshResults, error, ...restProps }: Searc placement: "bottom" }); + // Auto-focus. + useEffect(() => inputRef.current?.focus(), []); + useEffect(() => { if (error) { showTooltip(); diff --git a/apps/client/src/widgets/search_options/search_string.ts b/apps/client/src/widgets/search_options/search_string.ts deleted file mode 100644 index a1dec4710..000000000 --- a/apps/client/src/widgets/search_options/search_string.ts +++ /dev/null @@ -1,18 +0,0 @@ -import AbstractSearchOption from "./abstract_search_option.js"; -import SpacedUpdate from "../../services/spaced_update.js"; -import server from "../../services/server.js"; -import shortcutService from "../../services/shortcuts.js"; -import appContext, { type EventData } from "../../components/app_context.js"; -import { t } from "../../services/i18n.js"; -import { Tooltip } from "bootstrap"; - -export default class SearchString extends AbstractSearchOption { - - focusOnSearchDefinitionEvent() { - this.$searchString - .val(String(this.$searchString.val()).trim() ?? appContext.lastSearchString) - .focus() - .select(); - this.spacedUpdate.scheduleUpdate(); - } -}