fix(react/dialogs): entering command palette

This commit is contained in:
Elian Doran 2025-08-10 21:53:21 +03:00
parent 1ff77a1464
commit b94f67aa72
No known key found for this signature in database

View File

@ -15,7 +15,7 @@ const KEEP_LAST_SEARCH_FOR_X_SECONDS = 120;
type Mode = "last-search" | "recent-notes" | "commands"; type Mode = "last-search" | "recent-notes" | "commands";
function JumpToNoteDialogComponent() { function JumpToNoteDialogComponent() {
const [ mode, setMode ] = useState<Mode>("last-search"); const [ mode, setMode ] = useState<Mode>();
const [ lastOpenedTs, setLastOpenedTs ] = useState<number>(0); const [ lastOpenedTs, setLastOpenedTs ] = useState<number>(0);
const containerRef = useRef<HTMLDivElement>(null); const containerRef = useRef<HTMLDivElement>(null);
const autocompleteRef = useRef<HTMLInputElement>(null); const autocompleteRef = useRef<HTMLInputElement>(null);
@ -26,8 +26,10 @@ function JumpToNoteDialogComponent() {
async function openDialog(commandMode: boolean) { async function openDialog(commandMode: boolean) {
let newMode: Mode; let newMode: Mode;
let initialText: string = "";
if (commandMode) { if (commandMode) {
newMode = "commands"; newMode = "commands";
initialText = ">";
} else if (Date.now() - lastOpenedTs > KEEP_LAST_SEARCH_FOR_X_SECONDS * 1000) { } else if (Date.now() - lastOpenedTs > KEEP_LAST_SEARCH_FOR_X_SECONDS * 1000) {
// if you open the Jump To dialog soon after using it previously, it can often mean that you // if you open the Jump To dialog soon after using it previously, it can often mean that you
// actually want to search for the same thing (e.g., you opened the wrong note at first try) // actually want to search for the same thing (e.g., you opened the wrong note at first try)
@ -42,6 +44,7 @@ function JumpToNoteDialogComponent() {
setMode(newMode); setMode(newMode);
} }
setInitialText(initialText);
setShown(true); setShown(true);
setLastOpenedTs(Date.now()); setLastOpenedTs(Date.now());
} }