From 35bcf4af4955226dd5fd6f24ec6bacdbbe3919f7 Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Sat, 30 May 2026 18:11:41 -0700 Subject: [PATCH] Focus markdown link bubble input from ref (#3316) --- .../components/editor/RichMarkdownLinkBubble.tsx | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/renderer/src/components/editor/RichMarkdownLinkBubble.tsx b/src/renderer/src/components/editor/RichMarkdownLinkBubble.tsx index 9efe48441..5a033cdc5 100644 --- a/src/renderer/src/components/editor/RichMarkdownLinkBubble.tsx +++ b/src/renderer/src/components/editor/RichMarkdownLinkBubble.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useRef, useState } from 'react' +import React, { useCallback, useState } from 'react' import type { Editor } from '@tiptap/react' import { ExternalLink, Pencil, Unlink } from 'lucide-react' @@ -38,16 +38,20 @@ function LinkEditInput({ onCancel: () => void }): React.JSX.Element { const [value, setValue] = useState(initialHref) - const ref = useRef(null) - useEffect(() => { - ref.current?.focus() - ref.current?.select() + const setInputElement = useCallback((input: HTMLInputElement | null) => { + if (!input) { + return + } + // Why: edit mode should start with the current URL selected, but typing + // changes must not re-select the field on every value update. + input.focus() + input.select() }, []) return ( setValue(e.target.value)} onKeyDown={(e) => {