diff --git a/apps/client/src/widgets/dialogs/add_link.tsx b/apps/client/src/widgets/dialogs/add_link.tsx index 162d3b4f1..78867304c 100644 --- a/apps/client/src/widgets/dialogs/add_link.tsx +++ b/apps/client/src/widgets/dialogs/add_link.tsx @@ -17,7 +17,7 @@ type LinkType = "reference-link" | "external-link" | "hyper-link"; function AddLinkDialogComponent() { const [ textTypeWidget, setTextTypeWidget ] = useState(); - const [ text, setText ] = useState(); + const initialText = useRef(); const [ linkTitle, setLinkTitle ] = useState(""); const hasSelection = textTypeWidget?.hasSelection(); const [ linkType, setLinkType ] = useState(hasSelection ? "hyper-link" : "reference-link"); @@ -26,7 +26,7 @@ function AddLinkDialogComponent() { useTriliumEvent("showAddLinkDialog", ( { textTypeWidget, text }) => { setTextTypeWidget(textTypeWidget); - setText(text); + initialText.current = text; setShown(true); }); @@ -63,10 +63,10 @@ function AddLinkDialogComponent() { function onShown() { const $autocompleteEl = refToJQuerySelector(autocompleteRef); - if (!text) { + if (!initialText.current) { note_autocomplete.showRecentNotes($autocompleteEl); } else { - note_autocomplete.setText($autocompleteEl, text); + note_autocomplete.setText($autocompleteEl, initialText.current); } // to be able to quickly remove entered text @@ -110,7 +110,6 @@ function AddLinkDialogComponent() {