From 1ff77a1464bffadbc323a236b7c1b237ab6686b4 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 10 Aug 2025 21:00:38 +0300 Subject: [PATCH] fix(react/dialogs): jump to note not supporting spaces --- .../src/widgets/dialogs/jump_to_note.tsx | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/apps/client/src/widgets/dialogs/jump_to_note.tsx b/apps/client/src/widgets/dialogs/jump_to_note.tsx index 6f3e8457f..e7673b32e 100644 --- a/apps/client/src/widgets/dialogs/jump_to_note.tsx +++ b/apps/client/src/widgets/dialogs/jump_to_note.tsx @@ -3,7 +3,7 @@ import Modal from "../react/Modal"; import Button from "../react/Button"; import NoteAutocomplete from "../react/NoteAutocomplete"; import { t } from "../../services/i18n"; -import { useEffect, useRef, useState } from "preact/hooks"; +import { useRef, useState } from "preact/hooks"; import note_autocomplete, { Suggestion } from "../../services/note_autocomplete"; import appContext from "../../components/app_context"; import commandRegistry from "../../services/command_registry"; @@ -20,7 +20,8 @@ function JumpToNoteDialogComponent() { const containerRef = useRef(null); const autocompleteRef = useRef(null); const [ isCommandMode, setIsCommandMode ] = useState(mode === "commands"); - const [ text, setText ] = useState(isCommandMode ? "> " : ""); + const [ initialText, setInitialText ] = useState(isCommandMode ? "> " : ""); + const actualText = useRef(initialText); const [ shown, setShown ] = useState(false); async function openDialog(commandMode: boolean) { @@ -48,10 +49,6 @@ function JumpToNoteDialogComponent() { useTriliumEvent("jumpToNote", () => openDialog(false)); useTriliumEvent("commandPalette", () => openDialog(true)); - useEffect(() => { - setIsCommandMode(text.startsWith(">")); - }, [ text ]); - async function onItemSelected(suggestion?: Suggestion | null) { if (!suggestion) { return; @@ -70,7 +67,7 @@ function JumpToNoteDialogComponent() { switch (mode) { case "last-search": // Fall-through if there is no text, in order to display the recent notes. - if (text) { + if (initialText) { break; } case "recent-notes": @@ -94,14 +91,17 @@ function JumpToNoteDialogComponent() { placeholder={t("jump_to_note.search_placeholder")} inputRef={autocompleteRef} container={containerRef} - text={text} + text={initialText} opts={{ allowCreatingNotes: true, hideGoToSelectedNoteButton: true, allowJumpToSearchNotes: true, isCommandPalette: true }} - onTextChange={setText} + onTextChange={(text) => { + actualText.current = text; + setIsCommandMode(text.startsWith(">")); + }} onChange={onItemSelected} />} onShown={onShown}