From 1819f3e4e74167c1a6d42e2e3e5dfef9cfffa8ed Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Thu, 9 Nov 2023 11:23:39 +0000 Subject: [PATCH] Only focus the URL input when no URL has been entered (#15673) GitOrigin-RevId: e89406f5f0921898901c3c0d298e48e345a65621 --- .../components/command-tooltip/href-tooltip.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/services/web/frontend/js/features/source-editor/components/command-tooltip/href-tooltip.tsx b/services/web/frontend/js/features/source-editor/components/command-tooltip/href-tooltip.tsx index 221a0f3add..a0d681d9cb 100644 --- a/services/web/frontend/js/features/source-editor/components/command-tooltip/href-tooltip.tsx +++ b/services/web/frontend/js/features/source-editor/components/command-tooltip/href-tooltip.tsx @@ -41,9 +41,13 @@ export const HrefTooltipContent: FC = () => { { signal: controller.signal } ) - // focus the input element if there is content selected in the doc when the tooltip opens - if (!view.state.selection.main.empty) { - inputRef.current.focus() + // focus the URL input element when the tooltip opens, if the view is focused, + // there is content selected in the doc, and no URL has been entered + if (view.hasFocus && !view.state.selection.main.empty) { + const currentUrl = readUrl(view.state) + if (!currentUrl) { + inputRef.current.focus() + } } inputRef.current?.addEventListener(