summaryrefslogtreecommitdiff
path: root/node.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2023-08-13 13:10:56 -0300
committerpommicket <pommicket@gmail.com>2023-08-13 13:10:56 -0300
commit31c1f3acc7a56683b5512620419b8989a26dad4b (patch)
tree648fdec6c81f238903490f8c68092ad7241507fd /node.c
parent598d72c0674bb059c0f38f03c4851bcc61e5852d (diff)
documentation
Diffstat (limited to 'node.c')
-rw-r--r--node.c61
1 files changed, 30 insertions, 31 deletions
diff --git a/node.c b/node.c
index ae46a33..4382300 100644
--- a/node.c
+++ b/node.c
@@ -77,38 +77,37 @@ static u8 node_depth(Ted *ted, Node *node) {
void node_join(Ted *ted, Node *node) {
Node *parent = node_parent(ted, node);
- if (parent) {
- Node *a = parent->split_a;
- Node *b = parent->split_b;
- if (a->tabs && b->tabs) {
- if (ted->active_node == a || ted->active_node == b) {
- ted->active_node = parent;
- }
- arr_foreach_ptr(a->tabs, TextBufferPtr, tab) {
- arr_add(parent->tabs, *tab);
- }
- arr_foreach_ptr(b->tabs, TextBufferPtr, tab) {
- arr_add(parent->tabs, *tab);
- }
- if (!parent->tabs) {
- ted_out_of_mem(ted);
- return;
- }
-
- parent->split_a = NULL;
- parent->split_b = NULL;
- if (node == a) {
- parent->active_tab = a->active_tab;
- } else {
- parent->active_tab = (u16)arr_len(a->tabs) + b->active_tab;
- }
- node_free(a);
- node_free(b);
- arr_remove_item(ted->nodes, a);
- arr_remove_item(ted->nodes, b);
-
- }
+ if (!parent) return;
+
+ Node *a = parent->split_a;
+ Node *b = parent->split_b;
+ if (!(a->tabs && b->tabs)) return;
+
+ if (ted->active_node == a || ted->active_node == b) {
+ ted->active_node = parent;
+ }
+ arr_foreach_ptr(a->tabs, TextBufferPtr, tab) {
+ arr_add(parent->tabs, *tab);
+ }
+ arr_foreach_ptr(b->tabs, TextBufferPtr, tab) {
+ arr_add(parent->tabs, *tab);
+ }
+ if (!parent->tabs) {
+ ted_out_of_mem(ted);
+ return;
+ }
+
+ parent->split_a = NULL;
+ parent->split_b = NULL;
+ if (node == a) {
+ parent->active_tab = a->active_tab;
+ } else {
+ parent->active_tab = (u16)arr_len(a->tabs) + b->active_tab;
}
+ node_free(a);
+ node_free(b);
+ arr_remove_item(ted->nodes, a);
+ arr_remove_item(ted->nodes, b);
}
void node_close(Ted *ted, Node *node) {