1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 00:47:45 +00:00

Ladybird: Focus the location editor when creating a new tab

This lets you start typing a new URL right after pressing Ctrl+T.
This commit is contained in:
Andreas Kling 2022-09-12 09:12:04 +02:00 committed by Andrew Kaster
parent 031005de2d
commit 27b9cd13ee
3 changed files with 13 additions and 5 deletions

View file

@ -212,6 +212,8 @@ void BrowserWindow::new_tab()
if (m_tabs_container->count() > 1) if (m_tabs_container->count() > 1)
m_tabs_bar->show(); m_tabs_bar->show();
tab_ptr->focus_location_editor();
} }
void BrowserWindow::close_tab(int index) void BrowserWindow::close_tab(int index)

View file

@ -34,9 +34,9 @@ Tab::Tab(QMainWindow* window)
m_hover_label->setFrameShape(QFrame::Shape::Box); m_hover_label->setFrameShape(QFrame::Shape::Box);
m_hover_label->setAutoFillBackground(true); m_hover_label->setAutoFillBackground(true);
auto* focus_location_edit_action = new QAction("Edit Location"); auto* focus_location_editor_action = new QAction("Edit Location");
focus_location_edit_action->setShortcut(QKeySequence("Ctrl+L")); focus_location_editor_action->setShortcut(QKeySequence("Ctrl+L"));
addAction(focus_location_edit_action); addAction(focus_location_editor_action);
m_layout->addWidget(m_toolbar); m_layout->addWidget(m_toolbar);
m_layout->addWidget(m_view); m_layout->addWidget(m_view);
@ -80,8 +80,13 @@ Tab::Tab(QMainWindow* window)
QObject::connect(m_forward_action, &QAction::triggered, this, &Tab::forward); QObject::connect(m_forward_action, &QAction::triggered, this, &Tab::forward);
QObject::connect(m_home_action, &QAction::triggered, this, &Tab::home); QObject::connect(m_home_action, &QAction::triggered, this, &Tab::home);
QObject::connect(m_reload_action, &QAction::triggered, this, &Tab::reload); QObject::connect(m_reload_action, &QAction::triggered, this, &Tab::reload);
QObject::connect(focus_location_edit_action, &QAction::triggered, m_location_edit, qOverload<>(&QWidget::setFocus)); QObject::connect(focus_location_editor_action, &QAction::triggered, this, &Tab::focus_location_editor);
QObject::connect(focus_location_edit_action, &QAction::triggered, m_location_edit, &QLineEdit::selectAll); }
void Tab::focus_location_editor()
{
m_location_edit->setFocus();
m_location_edit->selectAll();
} }
void Tab::navigate(QString url) void Tab::navigate(QString url)

View file

@ -29,6 +29,7 @@ public:
void debug_request(String const& request, String const& argument); void debug_request(String const& request, String const& argument);
public slots: public slots:
void focus_location_editor();
void location_edit_return_pressed(); void location_edit_return_pressed();
void page_title_changed(QString); void page_title_changed(QString);
void page_favicon_changed(QIcon); void page_favicon_changed(QIcon);