Skip to content

Commit 5f37a78

Browse files
lolgearlucasderraugh
authored andcommitted
GraphView: Merged branches nodes selection via keyboard. (#581)
* kit: graph view merged branches nodes selection has been added. * kit: graph view merged branches typos have been fixed. * kit: graph view select side node nil layer guard has been added.
1 parent e25bf76 commit 5f37a78

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

GitUpKit/Interface/GIGraphView.m

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,31 @@ - (void)_selectChildNode {
376376
}
377377
}
378378

379+
- (void)_selectSideNodeAtPosition:(NSPoint)point {
380+
GILayer *layer = [self findLayerAtPosition:point.y];
381+
if (layer == nil) {
382+
return;
383+
}
384+
NSUInteger index = [layer.nodes indexOfObjectPassingTest:^BOOL(GINode * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
385+
return obj != _selectedNode && !obj.dummy;
386+
}];
387+
if (index != NSNotFound) {
388+
[self _setSelectedNode:layer.nodes[index] display:YES scroll:YES notify:YES];
389+
}
390+
}
391+
392+
- (void)_selectUncleNode {
393+
NSPoint position = [self positionForNode:_selectedNode];
394+
NSPoint targetPosition = NSMakePoint(position.x + kSpacingX, position.y - kSpacingY);
395+
[self _selectSideNodeAtPosition:targetPosition];
396+
}
397+
398+
- (void)_selectNephewNode {
399+
NSPoint position = [self positionForNode:_selectedNode];
400+
NSPoint targetPosition = NSMakePoint(position.x + kSpacingX, position.y + kSpacingY);
401+
[self _selectSideNodeAtPosition:targetPosition];
402+
}
403+
379404
- (void)_selectPreviousSiblingNode {
380405
NSArray* nodes = _selectedNode.layer.nodes;
381406
NSInteger index = [nodes indexOfObject:_selectedNode];
@@ -490,7 +515,9 @@ - (void)keyDown:(NSEvent*)event {
490515
return;
491516

492517
case kGIKeyCode_Down:
493-
if (event.modifierFlags & NSCommandKeyMask) {
518+
if (event.modifierFlags & NSAlternateKeyMask) {
519+
[self _selectUncleNode];
520+
} else if (event.modifierFlags & NSCommandKeyMask) {
494521
[self _scrollToBottom];
495522
} else if (_selectedNode) {
496523
[self _selectParentNode];
@@ -500,7 +527,9 @@ - (void)keyDown:(NSEvent*)event {
500527
return;
501528

502529
case kGIKeyCode_Up:
503-
if (event.modifierFlags & NSCommandKeyMask) {
530+
if (event.modifierFlags & NSAlternateKeyMask) {
531+
[self _selectNephewNode];
532+
} else if (event.modifierFlags & NSCommandKeyMask) {
504533
[self _scrollToTop];
505534
} else if (_selectedNode) {
506535
[self _selectChildNode];

0 commit comments

Comments
 (0)