From 27b9cd13ee778dca4e63883f04380c176e09730e Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 12 Sep 2022 09:12:04 +0200 Subject: [PATCH] Ladybird: Focus the location editor when creating a new tab This lets you start typing a new URL right after pressing Ctrl+T. --- Ladybird/BrowserWindow.cpp | 2 ++ Ladybird/Tab.cpp | 15 ++++++++++----- Ladybird/Tab.h | 1 + 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Ladybird/BrowserWindow.cpp b/Ladybird/BrowserWindow.cpp index d1e337f6de..a9ef368445 100644 --- a/Ladybird/BrowserWindow.cpp +++ b/Ladybird/BrowserWindow.cpp @@ -212,6 +212,8 @@ void BrowserWindow::new_tab() if (m_tabs_container->count() > 1) m_tabs_bar->show(); + + tab_ptr->focus_location_editor(); } void BrowserWindow::close_tab(int index) diff --git a/Ladybird/Tab.cpp b/Ladybird/Tab.cpp index a5e4fcf98e..b70d8cf77d 100644 --- a/Ladybird/Tab.cpp +++ b/Ladybird/Tab.cpp @@ -34,9 +34,9 @@ Tab::Tab(QMainWindow* window) m_hover_label->setFrameShape(QFrame::Shape::Box); m_hover_label->setAutoFillBackground(true); - auto* focus_location_edit_action = new QAction("Edit Location"); - focus_location_edit_action->setShortcut(QKeySequence("Ctrl+L")); - addAction(focus_location_edit_action); + auto* focus_location_editor_action = new QAction("Edit Location"); + focus_location_editor_action->setShortcut(QKeySequence("Ctrl+L")); + addAction(focus_location_editor_action); m_layout->addWidget(m_toolbar); 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_home_action, &QAction::triggered, this, &Tab::home); 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_edit_action, &QAction::triggered, m_location_edit, &QLineEdit::selectAll); + QObject::connect(focus_location_editor_action, &QAction::triggered, this, &Tab::focus_location_editor); +} + +void Tab::focus_location_editor() +{ + m_location_edit->setFocus(); + m_location_edit->selectAll(); } void Tab::navigate(QString url) diff --git a/Ladybird/Tab.h b/Ladybird/Tab.h index 12ed11c3a1..b6f6bf8830 100644 --- a/Ladybird/Tab.h +++ b/Ladybird/Tab.h @@ -29,6 +29,7 @@ public: void debug_request(String const& request, String const& argument); public slots: + void focus_location_editor(); void location_edit_return_pressed(); void page_title_changed(QString); void page_favicon_changed(QIcon);