Add hotkeys D and U move DiffView down/up by half page

This commit is contained in:
Ryan Jensen 2024-03-24 21:54:54 -05:00
parent 7e182735e2
commit 611052da32
2 changed files with 28 additions and 0 deletions

View File

@ -15,6 +15,7 @@
#include "CommentWidget.h"
#include "ui/DiffTreeModel.h"
#include "ui/DoubleTreeWidget.h"
#include "ui/HotkeyManager.h"
#include "git/Tree.h"
#include <QScrollBar>
#include <QPushButton>
@ -47,6 +48,12 @@ bool copy(const QString &source, const QDir &targetDir) {
} // namespace
static Hotkey moveHalfPageDownHotKey = HotkeyManager::registerHotkey(
"d", "diffView/moveHalfPageDownHotKey", "DiffView/Move Half Page Down");
static Hotkey moveHalfPageUpHotKey = HotkeyManager::registerHotkey(
"u", "diffView/moveHalfPageUpHotKey", "DiffView/Move Half Page Up");
DiffView::DiffView(const git::Repository &repo, QWidget *parent)
: QScrollArea(parent), mParent(parent) {
setStyleSheet(DiffViewStyle::kStyleSheet);
@ -84,6 +91,14 @@ DiffView::DiffView(const git::Repository &repo, QWidget *parent)
fetchMore();
});
}
QShortcut *shortcut = new QShortcut(this);
moveHalfPageDownHotKey.use(shortcut);
connect(shortcut, &QShortcut::activated, [this] { moveHalfPageDown(); });
shortcut = new QShortcut(this);
moveHalfPageUpHotKey.use(shortcut);
connect(shortcut, &QShortcut::activated, [this] { moveHalfPageUp(); });
}
DiffView::~DiffView() {}
@ -513,3 +528,13 @@ void DiffView::indexChanged(const QStringList &paths) {
// }
// }
}
void DiffView::moveHalfPageDown() { moveRelative(height() / 2); }
void DiffView::moveHalfPageUp() { moveRelative(-height() / 2); }
void DiffView::moveRelative(int pixelsDown) {
int oldPosition = verticalScrollBar()->sliderPosition();
int newPosition = oldPosition + pixelsDown;
verticalScrollBar()->setSliderPosition(newPosition);
}

View File

@ -103,6 +103,9 @@ public:
void diffTreeModelDataChanged(const QModelIndex &topLeft,
const QModelIndex &bottomRight,
const QVector<int> &roles);
void moveHalfPageDown();
void moveHalfPageUp();
void moveRelative(int pixelsDown);
signals:
void diagnosticAdded(TextEditor::DiagnosticKind kind);