From 770ac3c7a5d0107f62a122348447d862f5e36f2f Mon Sep 17 00:00:00 2001 From: Ryan Jensen Date: Wed, 20 Mar 2024 20:40:53 -0500 Subject: [PATCH 1/3] Add hotkeys: nextCommit and prevCommit --- src/ui/CommitList.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/ui/CommitList.cpp b/src/ui/CommitList.cpp index 49835ea3..7106daa0 100644 --- a/src/ui/CommitList.cpp +++ b/src/ui/CommitList.cpp @@ -28,6 +28,7 @@ #include "git/Signature.h" #include "git/TagRef.h" #include "git/Tree.h" +#include "ui/HotkeyManager.h" #include #include #include @@ -1168,6 +1169,12 @@ public: } // namespace +static Hotkey prevCommitHotKey = HotkeyManager::registerHotkey( + "J", "commitList/prevCommit", "CommitList/PrevCommit"); + +static Hotkey nextCommitHotKey = HotkeyManager::registerHotkey( + "K", "commitList/nextCommit", "CommitList/NextCommit"); + CommitList::CommitList(Index *index, QWidget *parent) : QListView(parent), mIndex(index) { Theme *theme = Application::theme(); @@ -1223,6 +1230,18 @@ CommitList::CommitList(Index *index, QWidget *parent) connect(this, &CommitList::entered, [this](const QModelIndex &index) { update(index); }); + QShortcut *shortcut = new QShortcut(this); + prevCommitHotKey.use(shortcut); + connect(shortcut, &QShortcut::activated, [this] { + printf("prevCommit\n"); + }); + + shortcut = new QShortcut(this); + nextCommitHotKey.use(shortcut); + connect(shortcut, &QShortcut::activated, [this] { + printf("nextCommit\n"); + }); + #ifdef Q_OS_MAC QFont font = this->font(); font.setPointSize(13); From 7e182735e29d7432bfab2962f29465396a3e76cf Mon Sep 17 00:00:00 2001 From: Ryan Jensen Date: Thu, 21 Mar 2024 00:01:02 -0500 Subject: [PATCH 2/3] Add selectCommitRelative() --- src/ui/CommitList.cpp | 34 ++++++++++++++++++++++------------ src/ui/CommitList.h | 1 + 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/ui/CommitList.cpp b/src/ui/CommitList.cpp index 7106daa0..8050d166 100644 --- a/src/ui/CommitList.cpp +++ b/src/ui/CommitList.cpp @@ -1169,11 +1169,11 @@ public: } // namespace -static Hotkey prevCommitHotKey = HotkeyManager::registerHotkey( - "J", "commitList/prevCommit", "CommitList/PrevCommit"); +static Hotkey selectCommitDownHotKey = HotkeyManager::registerHotkey( + "j", "commitList/selectCommitDown", "CommitList/Select Next Commit Down"); -static Hotkey nextCommitHotKey = HotkeyManager::registerHotkey( - "K", "commitList/nextCommit", "CommitList/NextCommit"); +static Hotkey selectCommitUpHotKey = HotkeyManager::registerHotkey( + "k", "commitList/selectCommitUp", "CommitList/Select Next Commit Up"); CommitList::CommitList(Index *index, QWidget *parent) : QListView(parent), mIndex(index) { @@ -1231,16 +1231,13 @@ CommitList::CommitList(Index *index, QWidget *parent) [this](const QModelIndex &index) { update(index); }); QShortcut *shortcut = new QShortcut(this); - prevCommitHotKey.use(shortcut); - connect(shortcut, &QShortcut::activated, [this] { - printf("prevCommit\n"); - }); + selectCommitDownHotKey.use(shortcut); + connect(shortcut, &QShortcut::activated, [this] { selectCommitRelative(1); }); shortcut = new QShortcut(this); - nextCommitHotKey.use(shortcut); - connect(shortcut, &QShortcut::activated, [this] { - printf("nextCommit\n"); - }); + selectCommitUpHotKey.use(shortcut); + connect(shortcut, &QShortcut::activated, + [this] { selectCommitRelative(-1); }); #ifdef Q_OS_MAC QFont font = this->font(); @@ -1364,6 +1361,19 @@ void CommitList::selectFirstCommit(bool spontaneous) { } } +void CommitList::selectCommitRelative(int offset) { + QModelIndexList indices = selectionModel()->selectedIndexes(); + QModelIndex index = indices[0]; + if (!index.isValid()) { + return; + } + QModelIndex new_index = model()->index(index.row() + offset, index.column()); + if (!new_index.isValid()) { + return; + } + selectIndexes(QItemSelection(new_index, new_index), QString(), true); +} + bool CommitList::selectRange(const QString &range, const QString &file, bool spontaneous) { // Try to select the "status" index. diff --git a/src/ui/CommitList.h b/src/ui/CommitList.h index fd0ffd16..ac236f6a 100644 --- a/src/ui/CommitList.h +++ b/src/ui/CommitList.h @@ -47,6 +47,7 @@ public: void selectReference(const git::Reference &ref); void resetSelection(bool spontaneous = false); void selectFirstCommit(bool spontaneous = false); + void selectCommitRelative(int offset); bool selectRange(const QString &range, const QString &file = QString(), bool spontaneous = false); void suppressResetWalker(bool suppress); From 611052da32a8c8471d900116414acd7642a1ec65 Mon Sep 17 00:00:00 2001 From: Ryan Jensen Date: Sun, 24 Mar 2024 21:54:54 -0500 Subject: [PATCH 3/3] Add hotkeys D and U move DiffView down/up by half page --- src/ui/DiffView/DiffView.cpp | 25 +++++++++++++++++++++++++ src/ui/DiffView/DiffView.h | 3 +++ 2 files changed, 28 insertions(+) diff --git a/src/ui/DiffView/DiffView.cpp b/src/ui/DiffView/DiffView.cpp index 4a4c2911..0418afcd 100644 --- a/src/ui/DiffView/DiffView.cpp +++ b/src/ui/DiffView/DiffView.cpp @@ -15,6 +15,7 @@ #include "CommentWidget.h" #include "ui/DiffTreeModel.h" #include "ui/DoubleTreeWidget.h" +#include "ui/HotkeyManager.h" #include "git/Tree.h" #include #include @@ -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); +} diff --git a/src/ui/DiffView/DiffView.h b/src/ui/DiffView/DiffView.h index 6ece8107..e72a8b18 100644 --- a/src/ui/DiffView/DiffView.h +++ b/src/ui/DiffView/DiffView.h @@ -103,6 +103,9 @@ public: void diffTreeModelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles); + void moveHalfPageDown(); + void moveHalfPageUp(); + void moveRelative(int pixelsDown); signals: void diagnosticAdded(TextEditor::DiagnosticKind kind);