fix(browser): preserve initial address bar drag selection

This commit is contained in:
Jinwoo-H
2026-09-06 16:44:11 -04:00
parent 80f748d9dc
commit a93e000bc6
@@ -53,6 +53,7 @@ export default function BrowserAddressBar({
const browserDefaultSearchEngine = useAppStore((s) => s.browserDefaultSearchEngine)
const browserKagiSessionLink = useAppStore((s) => s.browserKagiSessionLink)
const closingRef = useRef(false)
const initialMouseDownRef = useRef(false)
const openedAtRef = useRef(0)
const blurCloseTimerRef = useRef<number | null>(null)
const closingResetTimerRef = useRef<number | null>(null)
@@ -241,12 +242,15 @@ export default function BrowserAddressBar({
window.clearTimeout(blurCloseTimerRef.current)
blurCloseTimerRef.current = null
}
inputRef.current?.select()
if (!initialMouseDownRef.current) {
inputRef.current?.select()
}
openedAtRef.current = Date.now()
setOpen(true)
}, [inputRef])
const handleBlur = useCallback(() => {
initialMouseDownRef.current = false
// Why: delay close so that clicking a suggestion item registers before
// the popover unmounts. Without this, onSelect never fires because the
// mousedown on PopoverContent triggers input blur first.
@@ -425,11 +429,16 @@ export default function BrowserAddressBar({
value={value}
onFocus={handleFocus}
onMouseDown={(event) => {
if (event.button === 0 && document.activeElement !== event.currentTarget) {
// Keep the initial click from overriding the focus handler's full selection.
event.preventDefault()
event.currentTarget.focus()
initialMouseDownRef.current =
event.button === 0 && document.activeElement !== event.currentTarget
}}
onClick={(event) => {
const input = event.currentTarget
// Preserve native drag selection; only expand a collapsed initial click.
if (initialMouseDownRef.current && input.selectionStart === input.selectionEnd) {
input.select()
}
initialMouseDownRef.current = false
}}
onBlur={handleBlur}
onKeyDown={handleKeyDown}