Skip to content

Build your personal knowledge base with Trilium Notes

chore(react/ribbon): focus on search textbox

Elian Doran3f105f7b8b51
diff --git a/apps/client/src/components/app_context.ts b/apps/client/src/components/app_context.ts
index 35b8b85855..319988aa4d 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<CommandData>;
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 8e7df94940..632eb0a887 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 2f202fe120..94de4f6fd3 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 a1dec47100..0000000000
--- 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();
- }
-}