Skip to content

Commit cf6f49d

Browse files
authoredMay 26, 2023
Add key navigation between index and workdir files (#921)
* Add key navigation between index and workdir files Navigate to index files controller when Down button pressed while on the last file of the workdir list Navigate to workdir files controller when Up button pressed while on the first files of the index list * Use NSEventModifierFlags for declared modifiers Use more precise type for long flags
1 parent ecff963 commit cf6f49d

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed
 

‎GitUpKit/Interface/GIConstants.h

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// You should have received a copy of the GNU General Public License
1414
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1515

16+
#import <AppKit/NSEvent.h>
1617
#import <Foundation/Foundation.h>
1718

1819
typedef NS_ENUM(unsigned short, GIKeyCode) {
@@ -29,3 +30,5 @@ typedef NS_ENUM(unsigned short, GIKeyCode) {
2930
kGIKeyCode_Return = 0x24,
3031
kGIKeyCode_Delete = 0x33
3132
};
33+
34+
static const NSEventModifierFlags kGIKeyModifiersAll = NSEventModifierFlagShift | NSEventModifierFlagControl | NSEventModifierFlagCommand | NSEventModifierFlagOption;

‎GitUpKit/Views/GIAdvancedCommitViewController.m

+22
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ - (void)_diffFilesViewControllerDidPressDelete:(GIDiffFilesViewController*)contr
309309
}
310310

311311
- (BOOL)diffFilesViewController:(GIDiffFilesViewController*)controller handleKeyDownEvent:(NSEvent*)event {
312+
// Stage/Unstage files by Return/Delete
312313
if (!(event.modifierFlags & NSEventModifierFlagDeviceIndependentFlagsMask)) {
313314
if (event.keyCode == kGIKeyCode_Return) {
314315
[self _diffFilesViewControllerDidPressReturn:controller];
@@ -319,6 +320,27 @@ - (BOOL)diffFilesViewController:(GIDiffFilesViewController*)controller handleKey
319320
}
320321
}
321322

323+
// Navigate beteween stated and unstaged files list by up/down arrows
324+
NSEventModifierFlags modifiers = event.modifierFlags & kGIKeyModifiersAll;
325+
if (controller == _workdirFilesViewController && !modifiers && event.keyCode == kGIKeyCode_Down) {
326+
bool onlyLastFileSelected = (controller.selectedDeltas.count == 1) && (controller.selectedDelta == controller.deltas.lastObject);
327+
bool hasIndexFiles = _indexFilesViewController.deltas.count > 0;
328+
if (onlyLastFileSelected && hasIndexFiles) {
329+
// move focus to next controller
330+
[[controller.view window] selectNextKeyView:_workdirFilesViewController.view];
331+
return YES;
332+
}
333+
} else if (controller == _indexFilesViewController && !modifiers && event.keyCode == kGIKeyCode_Up) {
334+
bool onlyFirstFileSelected = (controller.selectedDeltas.count == 1) && (controller.selectedDelta == controller.deltas.firstObject);
335+
bool hasWorkdirFiles =_workdirFilesViewController.deltas.count > 0;
336+
if (onlyFirstFileSelected && hasWorkdirFiles) {
337+
// move focus to previous controller
338+
[[controller.view window] selectPreviousKeyView:_workdirFilesViewController.view];
339+
return YES;
340+
}
341+
}
342+
343+
// Perform contextual action on a file
322344
if (controller == _workdirFilesViewController) {
323345
return [self handleKeyDownEvent:event forSelectedDeltas:_workdirFilesViewController.selectedDeltas withConflicts:_indexConflicts allowOpen:YES];
324346
} else if (controller == _indexFilesViewController) {

0 commit comments

Comments
 (0)
Please sign in to comment.