From d6796d5123872de0c18f44a305318a6418eaf546 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Harald=20J=C3=B8rgensen?= <58829763+adamjoer@users.noreply.github.com> Date: Wed, 20 Sep 2023 11:32:37 +0200 Subject: [PATCH] Ladybird: Add keyboard shortcuts for jumping to a specific tab It's now possible to open a specific tab by using Ctrl/Command plus the number key corresponding to its position in the tab row. --- Ladybird/Qt/BrowserWindow.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Ladybird/Qt/BrowserWindow.cpp b/Ladybird/Qt/BrowserWindow.cpp index bf4fe68441..acbf53bd90 100644 --- a/Ladybird/Qt/BrowserWindow.cpp +++ b/Ladybird/Qt/BrowserWindow.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include namespace Ladybird { @@ -406,6 +407,22 @@ BrowserWindow::BrowserWindow(Vector const& initial_urls, WebView::CookieJar m_go_forward_action->setEnabled(false); m_reload_action->setEnabled(false); + for (int i = 0; i <= 7; ++i) { + new QShortcut(QKeySequence(Qt::CTRL | static_cast(Qt::Key_1 + i)), this, [this, i] { + if (m_tabs_container->count() <= 1) + return; + + m_tabs_container->setCurrentIndex(min(i, m_tabs_container->count() - 1)); + }); + } + + new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_9), this, [this] { + if (m_tabs_container->count() <= 1) + return; + + m_tabs_container->setCurrentIndex(m_tabs_container->count() - 1); + }); + if (!initial_urls.is_empty()) { bool is_first_tab = true; for (auto const& url : initial_urls) {