Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add key navigation between index and workdir files #921

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions GitUpKit/Interface/GIConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

#import <AppKit/NSEvent.h>
#import <Foundation/Foundation.h>

typedef NS_ENUM(unsigned short, GIKeyCode) {
Expand All @@ -29,3 +30,5 @@ typedef NS_ENUM(unsigned short, GIKeyCode) {
kGIKeyCode_Return = 0x24,
kGIKeyCode_Delete = 0x33
};

static const NSEventModifierFlags kGIKeyModifiersAll = NSEventModifierFlagShift | NSEventModifierFlagControl | NSEventModifierFlagCommand | NSEventModifierFlagOption;
22 changes: 22 additions & 0 deletions GitUpKit/Views/GIAdvancedCommitViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ - (void)_diffFilesViewControllerDidPressDelete:(GIDiffFilesViewController*)contr
}

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

// Navigate beteween stated and unstaged files list by up/down arrows
NSEventModifierFlags modifiers = event.modifierFlags & kGIKeyModifiersAll;
if (controller == _workdirFilesViewController && !modifiers && event.keyCode == kGIKeyCode_Down) {
bool onlyLastFileSelected = (controller.selectedDeltas.count == 1) && (controller.selectedDelta == controller.deltas.lastObject);
bool hasIndexFiles = _indexFilesViewController.deltas.count > 0;
if (onlyLastFileSelected && hasIndexFiles) {
// move focus to next controller
[[controller.view window] selectNextKeyView:_workdirFilesViewController.view];
return YES;
}
} else if (controller == _indexFilesViewController && !modifiers && event.keyCode == kGIKeyCode_Up) {
bool onlyFirstFileSelected = (controller.selectedDeltas.count == 1) && (controller.selectedDelta == controller.deltas.firstObject);
bool hasWorkdirFiles =_workdirFilesViewController.deltas.count > 0;
if (onlyFirstFileSelected && hasWorkdirFiles) {
// move focus to previous controller
[[controller.view window] selectPreviousKeyView:_workdirFilesViewController.view];
return YES;
}
}

// Perform contextual action on a file
if (controller == _workdirFilesViewController) {
return [self handleKeyDownEvent:event forSelectedDeltas:_workdirFilesViewController.selectedDeltas withConflicts:_indexConflicts allowOpen:YES];
} else if (controller == _indexFilesViewController) {
Expand Down