mirror of
https://github.com/stablyai/orca.git
synced 2026-09-22 00:02:31 +00:00
Focus markdown preview search input from ref (#3322)
This commit is contained in:
@@ -434,6 +434,16 @@ export default function MarkdownPreview({
|
||||
const rootRef = useRef<HTMLDivElement>(null)
|
||||
const bodyRef = useRef<HTMLDivElement>(null)
|
||||
const inputRef = useRef<HTMLInputElement>(null)
|
||||
const setSearchInputElement = useCallback((input: HTMLInputElement | null) => {
|
||||
inputRef.current = input
|
||||
if (!input) {
|
||||
return
|
||||
}
|
||||
// Why: opening preview search should select the query once, while typing
|
||||
// and match-count updates must not keep re-selecting the field.
|
||||
input.focus()
|
||||
input.select()
|
||||
}, [])
|
||||
const matchesRef = useRef<HTMLElement[]>([])
|
||||
const lastAppliedInitialAnchorRef = useRef<string | null>(null)
|
||||
const pendingEditorRevealFrameIdsRef = useRef<number[]>([])
|
||||
@@ -747,13 +757,6 @@ export default function MarkdownPreview({
|
||||
[scrollToAnchor]
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
if (isSearchOpen) {
|
||||
inputRef.current?.focus()
|
||||
inputRef.current?.select()
|
||||
}
|
||||
}, [isSearchOpen])
|
||||
|
||||
useEffect(() => {
|
||||
const body = bodyRef.current
|
||||
if (!body) {
|
||||
@@ -1565,7 +1568,7 @@ export default function MarkdownPreview({
|
||||
<div className="markdown-preview-search" onKeyDown={(event) => event.stopPropagation()}>
|
||||
<div className="markdown-preview-search-field">
|
||||
<Input
|
||||
ref={inputRef}
|
||||
ref={setSearchInputElement}
|
||||
value={query}
|
||||
onChange={(event) => setQuery(event.target.value)}
|
||||
onKeyDown={(event) => {
|
||||
|
||||
Reference in New Issue
Block a user