7a61abddb9a45ee0c237e0fb6e1ba16d9dc879b5

Author
outfoxxed <outfoxxed@outfoxxed.me>
Committer
outfoxxed <outfoxxed@outfoxxed.me>
Date

Message

Extract shift / layout comparisons to functions

Diff

 1diff --git a/src/Hy3Layout.cpp b/src/Hy3Layout.cpp
 2index 1118d2fc2cf0bec929309bf81f4d29c3b24eab6f..faaa283c29ca30d95277856ba6d221a0c38360e5 100644
 3--- a/src/Hy3Layout.cpp
 4+++ b/src/Hy3Layout.cpp
 5@@ -979,8 +979,16 @@ bool shiftIsForward(ShiftDirection direction) {
 6 	return direction == ShiftDirection::Right || direction == ShiftDirection::Down;
 7 }
 8 
 9-Hy3Node* Hy3Layout::shiftOrGetFocus(Hy3Node& node, ShiftDirection direction, bool shift) {
10+bool shiftIsVertical(ShiftDirection direction) {
11+	return direction == ShiftDirection::Up || direction == ShiftDirection::Down;
12+}
13+
14+bool shiftMatchesLayout(Hy3GroupLayout layout, ShiftDirection direction) {
15+	return (layout == Hy3GroupLayout::SplitV && shiftIsVertical(direction))
16+		|| (layout != Hy3GroupLayout::SplitV && !shiftIsVertical(direction));
17+}
18 
19+Hy3Node* Hy3Layout::shiftOrGetFocus(Hy3Node& node, ShiftDirection direction, bool shift) {
20 	auto* break_origin = &node;
21 	auto* break_parent = break_origin->parent;
22 
23@@ -990,11 +998,7 @@ Hy3Node* Hy3Layout::shiftOrGetFocus(Hy3Node& node, ShiftDirection direction, boo
24 
25 		auto& group = break_parent->data.as_group; // must be a group in order to be a parent
26 
27-		if (((group.layout == Hy3GroupLayout::SplitH || group.layout == Hy3GroupLayout::Tabbed)
28-				 && (direction == ShiftDirection::Left || direction == ShiftDirection::Right))
29-				|| (group.layout == Hy3GroupLayout::SplitV
30-						&& (direction == ShiftDirection::Up || direction == ShiftDirection::Down)))
31-		{
32+		if (shiftMatchesLayout(group.layout, direction)) {
33 			// group has the correct orientation
34 
35 			// if this movement would break out of the group, continue the break loop (do not enter this if)
36@@ -1049,11 +1053,7 @@ Hy3Node* Hy3Layout::shiftOrGetFocus(Hy3Node& node, ShiftDirection direction, boo
37 
38 				bool shift_after = false;
39 
40-				if (((group_data.layout == Hy3GroupLayout::SplitH || group_data.layout == Hy3GroupLayout::Tabbed)
41-						 && (direction == ShiftDirection::Left || direction == ShiftDirection::Right))
42-						|| (group_data.layout == Hy3GroupLayout::SplitV
43-								&& (direction == ShiftDirection::Up || direction == ShiftDirection::Down)))
44-				{
45+				if (shiftMatchesLayout(group_data.layout, direction)) {
46 					// if the group has the same orientation as movement pick the last/first child based
47 					// on movement direction
48 					if (shiftIsForward(direction)) iter = group_data.children.begin();