diff options
author | pommicket <pommicket@gmail.com> | 2023-08-15 17:07:59 -0300 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2023-08-15 17:24:36 -0300 |
commit | da57a4738f0d447d9c8bf322c486de6b3e177c48 (patch) | |
tree | 02296a64b5574153fee50fc57c9a021e98cad965 /node.c | |
parent | 87845777777058fa45c93df15e67b65ad41708a7 (diff) |
fix node bug2.5
Diffstat (limited to 'node.c')
-rw-r--r-- | node.c | 34 |
1 files changed, 13 insertions, 21 deletions
@@ -93,27 +93,12 @@ bool node_add_tab(Ted *ted, Node *node, TextBuffer *buffer) { return true; } -static void node_switch_to_tab(Ted *ted, Node *node, u16 new_tab_index) { - if (new_tab_index >= arr_len(node->tabs)) - return; - if (new_tab_index == node->active_tab) - return; - - node->active_tab = new_tab_index; - if (node == ted->active_node) { - // switch active buffer - assert(node->tabs); - TextBuffer *buffer = node->tabs[new_tab_index]; - ted_switch_to_buffer(ted, buffer); - } -} - // move n tabs to the right void node_tab_next(Ted *ted, Node *node, i32 n) { - u16 ntabs = (u16)arr_len(node->tabs); + u32 ntabs = arr_len(node->tabs); if (!ntabs) return; - u16 tab_idx = (u16)mod_i64((i64)node->active_tab + n, ntabs); - node_switch_to_tab(ted, node, tab_idx); + u32 tab_idx = (u32)mod_i64((i64)node->active_tab + n, ntabs); + node_tab_switch(ted, node, tab_idx); } void node_tab_prev(Ted *ted, Node *node, i32 n) { @@ -122,8 +107,15 @@ void node_tab_prev(Ted *ted, Node *node, i32 n) { void node_tab_switch(Ted *ted, Node *node, u32 tab) { assert(node->tabs); - if (tab >= 0 && tab < node_tab_count(node)) { - node_switch_to_tab(ted, node, (u16)tab); + if (tab >= arr_len(node->tabs)) + return; + + node->active_tab = (u16)tab; + if (node == ted->active_node) { + // switch active buffer + assert(node->tabs); + TextBuffer *buffer = node->tabs[tab]; + ted_switch_to_buffer(ted, buffer); } } @@ -311,7 +303,7 @@ void node_frame(Ted *ted, Node *node, Rect r) { u16 tab_index = (u16)((click->pos.x - r.pos.x) / tab_width); if (tab_index < arr_len(node->tabs)) { ted->active_node = node; - node_switch_to_tab(ted, node, tab_index); + node_tab_switch(ted, node, tab_index); ted->dragging_tab_node = node; ted->dragging_tab_idx = tab_index; ted->dragging_tab_origin = click->pos; |