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.
This commit is contained in:
Adam Harald Jørgensen 2023-09-20 11:32:37 +02:00 committed by Andreas Kling
parent f2f98b7938
commit d6796d5123
Notes: sideshowbarker 2024-07-16 23:52:22 +09:00

View File

@ -25,6 +25,7 @@
#include <QGuiApplication>
#include <QInputDialog>
#include <QPlainTextEdit>
#include <QShortcut>
#include <QTabBar>
namespace Ladybird {
@ -406,6 +407,22 @@ BrowserWindow::BrowserWindow(Vector<URL> 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>(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) {