UI/AppKit: Restore focus when activating a tab

Tabs opened from links on AppKit can be created before their URL is
loaded. That left background open-url tabs with the location field as
their stored responder, so switching to them later restored address-bar
focus instead of web content focus.

Track each tab's preferred responder, restore it when AppKit makes
the tab key, and mark page-backed open-url tabs to prefer the web view.
Blank new-tab pages still keep the location field focused.
This commit is contained in:
Andreas Kling
2026-04-16 23:20:18 +02:00
committed by Andreas Kling
parent 1572429541
commit 71d92c7298
Notes: github-actions[bot] 2026-04-17 06:07:22 +00:00
6 changed files with 34 additions and 3 deletions

View File

@@ -329,9 +329,8 @@ static NSInteger autocomplete_suggestion_index(NSString* suggestion_text, Vector
[self setLocationFieldText:url.serialize()];
// 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];
}
if (url != WebView::Application::settings().new_tab_page_url())
[self focusWebView];
}
- (void)onEnterFullscreenWindow
@@ -353,9 +352,21 @@ static NSInteger autocomplete_suggestion_index(NSString* suggestion_text, Vector
- (void)focusLocationToolbarItem
{
[self tab].preferred_first_responder = self.location_toolbar_item.view;
[self.window makeFirstResponder:self.location_toolbar_item.view];
}
- (void)focusWebViewWhenActivated
{
[self tab].preferred_first_responder = [self tab].web_view;
}
- (void)focusWebView
{
[self tab].preferred_first_responder = [self tab].web_view;
[self.window makeFirstResponder:[self tab].web_view];
}
#pragma mark - Private methods
- (Tab*)tab