mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-02 20:42:11 +02:00
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:
committed by
Andreas Kling
parent
1572429541
commit
71d92c7298
Notes:
github-actions[bot]
2026-04-17 06:07:22 +00:00
Author: https://github.com/awesomekling Commit: https://github.com/LadybirdBrowser/ladybird/commit/71d92c72988 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/8950
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user