Skip to content

Commit 0f1644f

Browse files
awesomeklingADKaster
authored andcommitted
Ladybird: Switch to next/previous tab with Ctrl+PageDown/PageUp
1 parent 27b9cd1 commit 0f1644f

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

Ladybird/BrowserWindow.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ BrowserWindow::BrowserWindow()
4646
quit_action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_Q));
4747
menu->addAction(quit_action);
4848

49+
auto* view_menu = menuBar()->addMenu("&View");
50+
51+
auto* open_next_tab_action = new QAction("Open &Next Tab");
52+
open_next_tab_action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_PageDown));
53+
view_menu->addAction(open_next_tab_action);
54+
QObject::connect(open_next_tab_action, &QAction::triggered, this, &BrowserWindow::open_next_tab);
55+
56+
auto* open_previous_tab_action = new QAction("Open &Previous Tab");
57+
open_previous_tab_action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_PageUp));
58+
view_menu->addAction(open_previous_tab_action);
59+
QObject::connect(open_previous_tab_action, &QAction::triggered, this, &BrowserWindow::open_previous_tab);
60+
4961
auto* inspect_menu = menuBar()->addMenu("&Inspect");
5062

5163
auto* view_source_action = new QAction("View &Source");
@@ -258,3 +270,25 @@ void BrowserWindow::tab_favicon_changed(int index, QIcon icon)
258270
m_tabs_container->setTabIcon(index, icon);
259271
setWindowIcon(icon);
260272
}
273+
274+
void BrowserWindow::open_next_tab()
275+
{
276+
if (m_tabs_container->count() <= 1)
277+
return;
278+
279+
auto next_index = m_tabs_container->currentIndex() + 1;
280+
if (next_index >= m_tabs_container->count())
281+
next_index = 0;
282+
m_tabs_container->setCurrentIndex(next_index);
283+
}
284+
285+
void BrowserWindow::open_previous_tab()
286+
{
287+
if (m_tabs_container->count() <= 1)
288+
return;
289+
290+
auto next_index = m_tabs_container->currentIndex() - 1;
291+
if (next_index < 0)
292+
next_index = m_tabs_container->count() - 1;
293+
m_tabs_container->setCurrentIndex(next_index);
294+
}

Ladybird/BrowserWindow.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public slots:
3434
void new_tab();
3535
void close_tab(int index);
3636
void close_current_tab();
37+
void open_next_tab();
38+
void open_previous_tab();
3739

3840
private:
3941
void debug_request(String const& request, String const& argument = "");

0 commit comments

Comments
 (0)