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
This commit is contained in:
SvDp 2025-11-24 23:43:51 +05:30 committed by Jelle Raaijmakers
parent aac387bcc6
commit 5b7c9af340
Notes: github-actions[bot] 2025-11-26 09:49:09 +00:00
2 changed files with 6 additions and 1 deletions

View file

@ -189,6 +189,7 @@
if (activate_tab == Web::HTML::ActivateTab::Yes) { if (activate_tab == Web::HTML::ActivateTab::Yes) {
[[controller window] orderFrontRegardless]; [[controller window] orderFrontRegardless];
[controller focusLocationToolbarItem];
} }
[self.managed_tabs addObject:controller]; [self.managed_tabs addObject:controller];

View file

@ -145,7 +145,11 @@ static NSString* const TOOLBAR_TAB_OVERVIEW_IDENTIFIER = @"ToolbarTabOverviewIde
- (void)onURLChange:(URL::URL const&)url - (void)onURLChange:(URL::URL const&)url
{ {
[self setLocationFieldText:url.serialize()]; [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 - (void)clearHistory