From 5b7c9af34038043024acb38fa66ab8a6f9e9617d Mon Sep 17 00:00:00 2001 From: SvDp Date: Mon, 24 Nov 2025 23:43:51 +0530 Subject: [PATCH] UI/AppKit: Auto-focus location bar when opening new tabs on macOS When a new tab is created, the location bar should automatically receive keyboard focus so users can immediately start typing a URL. However, the onURLChange callback was stealing focus back to the web view when loading the new tab page. This fix: 1. Calls focusLocationToolbarItem when activating a new tab 2. Prevents onURLChange from stealing focus when loading the new tab page URL Fixes #1512 --- UI/AppKit/Application/ApplicationDelegate.mm | 1 + UI/AppKit/Interface/TabController.mm | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/UI/AppKit/Application/ApplicationDelegate.mm b/UI/AppKit/Application/ApplicationDelegate.mm index c5d96022284..bc25bb251f9 100644 --- a/UI/AppKit/Application/ApplicationDelegate.mm +++ b/UI/AppKit/Application/ApplicationDelegate.mm @@ -189,6 +189,7 @@ if (activate_tab == Web::HTML::ActivateTab::Yes) { [[controller window] orderFrontRegardless]; + [controller focusLocationToolbarItem]; } [self.managed_tabs addObject:controller]; diff --git a/UI/AppKit/Interface/TabController.mm b/UI/AppKit/Interface/TabController.mm index 233a32636b5..8e4cbfc2279 100644 --- a/UI/AppKit/Interface/TabController.mm +++ b/UI/AppKit/Interface/TabController.mm @@ -145,7 +145,11 @@ static NSString* const TOOLBAR_TAB_OVERVIEW_IDENTIFIER = @"ToolbarTabOverviewIde - (void)onURLChange:(URL::URL const&)url { [self setLocationFieldText:url.serialize()]; - [self.window makeFirstResponder:[self tab].web_view]; + + // Don't steal focus from the location bar when loading the new tab page + if (url != WebView::Application::settings().new_tab_page_url()) { + [self.window makeFirstResponder:[self tab].web_view]; + } } - (void)clearHistory