mirror of
https://github.com/KDE/konsole.git
synced 2025-12-23 23:38:08 -05:00
Add two keyboard actions for focusing on next/prev in split view mode
This commit adds two keyboard action for focusing on next or previous view in split view tab. The default shortcuts are `ctrl-F11` for next view and `ctrl=shift-F11` for previous view. I find these shortcuts more useful in some situations than the currently available shortcuts for moving the focus up/down/left/right. The order of the views in the list is the one returned by `ViewSplitter::findChildren<TerminalDisplay *>`, so it does not correlate exactly to their positions.
This commit is contained in:
committed by
Kurt Hindenburg
parent
8ed45adea0
commit
53b3a06f00
@@ -279,6 +279,18 @@ void ViewManager::setupActions()
|
||||
collection->addAction(QStringLiteral("focus-view-right"), action);
|
||||
_multiSplitterOnlyActions << action;
|
||||
|
||||
action = new QAction(i18nc("@action Shortcut entry", "Focus Next Terminal"), this);
|
||||
collection->setDefaultShortcut(action, Qt::CTRL | Qt::Key_F11);
|
||||
connect(action, &QAction::triggered, this, &ViewManager::focusNext);
|
||||
collection->addAction(QStringLiteral("focus-view-next"), action);
|
||||
_multiSplitterOnlyActions << action;
|
||||
|
||||
action = new QAction(i18nc("@action Shortcut entry", "Focus Previous Terminal"), this);
|
||||
collection->setDefaultShortcut(action, Qt::CTRL | Qt::SHIFT | Qt::Key_F11);
|
||||
connect(action, &QAction::triggered, this, &ViewManager::focusPrev);
|
||||
collection->addAction(QStringLiteral("focus-view-prev"), action);
|
||||
_multiSplitterOnlyActions << action;
|
||||
|
||||
action = new QAction(i18nc("@action Shortcut entry", "Switch to Last Tab"), this);
|
||||
connect(action, &QAction::triggered, this, &ViewManager::lastView);
|
||||
collection->addAction(QStringLiteral("last-tab"), action);
|
||||
@@ -439,6 +451,16 @@ void ViewManager::focusRight()
|
||||
_viewContainer->activeViewSplitter()->focusRight();
|
||||
}
|
||||
|
||||
void ViewManager::focusNext()
|
||||
{
|
||||
_viewContainer->activeViewSplitter()->focusNext();
|
||||
}
|
||||
|
||||
void ViewManager::focusPrev()
|
||||
{
|
||||
_viewContainer->activeViewSplitter()->focusPrev();
|
||||
}
|
||||
|
||||
void ViewManager::moveActiveViewLeft()
|
||||
{
|
||||
_viewContainer->moveActiveView(TabbedViewContainer::MoveViewLeft);
|
||||
|
||||
@@ -410,6 +410,9 @@ private Q_SLOTS:
|
||||
void focusLeft();
|
||||
void focusRight();
|
||||
|
||||
void focusNext();
|
||||
void focusPrev();
|
||||
|
||||
// called when "Next View" shortcut is activated
|
||||
void nextView();
|
||||
|
||||
|
||||
@@ -290,6 +290,30 @@ void ViewSplitter::focusRight()
|
||||
handleFocusDirection(Qt::Horizontal, +1);
|
||||
}
|
||||
|
||||
void ViewSplitter::focusNext(int dir)
|
||||
{
|
||||
auto terminalDisplay = activeTerminalDisplay();
|
||||
auto parentSplitter = qobject_cast<ViewSplitter *>(terminalDisplay->parentWidget());
|
||||
auto topSplitter = parentSplitter->getToplevelSplitter();
|
||||
auto terminals = topSplitter->findChildren<TerminalDisplay *>();
|
||||
int id = terminals.indexOf(terminalDisplay);
|
||||
int targetId = (id + dir) % terminals.size();
|
||||
if (targetId < 0) {
|
||||
targetId = terminals.size() + targetId;
|
||||
}
|
||||
|
||||
auto targetTerminal = terminals.at(targetId);
|
||||
|
||||
if (targetTerminal) {
|
||||
targetTerminal->setFocus(Qt::OtherFocusReason);
|
||||
}
|
||||
}
|
||||
|
||||
void ViewSplitter::focusPrev()
|
||||
{
|
||||
focusNext(-1);
|
||||
}
|
||||
|
||||
TerminalDisplay *ViewSplitter::activeTerminalDisplay() const
|
||||
{
|
||||
auto focusedWidget = focusWidget();
|
||||
|
||||
@@ -145,6 +145,9 @@ public:
|
||||
void focusLeft();
|
||||
void focusRight();
|
||||
|
||||
void focusNext(int dir = 1);
|
||||
void focusPrev();
|
||||
|
||||
void handleFocusDirection(Qt::Orientation orientation, int direction);
|
||||
|
||||
void childEvent(QChildEvent *event) override;
|
||||
|
||||
Reference in New Issue
Block a user