Skip to content

Commit

Permalink
Add hotkeys D and U move DiffView down/up by half page
Browse files Browse the repository at this point in the history
  • Loading branch information
jensenr30 committed Mar 25, 2024
1 parent 7e18273 commit 611052d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/ui/DiffView/DiffView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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() {}
Expand Down Expand Up @@ -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);
}
3 changes: 3 additions & 0 deletions src/ui/DiffView/DiffView.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ class DiffView : public QScrollArea, public EditorProvider {
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);
Expand Down

0 comments on commit 611052d

Please sign in to comment.