diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2021-03-01 20:15:33 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2021-03-01 21:37:49 -0500 |
commit | 966197c46b09539c410c8e9c04e83dfc41a796a6 (patch) | |
tree | d0f38856a95f6b7fbc871d795c6d3b645d12a9be | |
parent | 04bedad8ef1f6f92873d7bed67f0017db4095e77 (diff) |
fix active_node after tab close
-rw-r--r-- | node.c | 8 |
1 files changed, 4 insertions, 4 deletions
@@ -156,10 +156,10 @@ static bool node_tab_close(Ted *ted, Node *node, u16 index) { node_close(ted, (u16)(node - ted->nodes)); return false; } else { + bool was_active = ted->active_node == node; // ted->active_node will be set to NULL when the active buffer is deleted. u16 buffer_index = node->tabs[index]; // remove tab from array - memmove(&node->tabs[index], &node->tabs[index + 1], (size_t)(ntabs - (index + 1)) * sizeof *node->tabs); - arr_remove_last(node->tabs); + arr_remove(node->tabs, index); ted_delete_buffer(ted, buffer_index); ntabs = (u16)arr_len(node->tabs); // update ntabs @@ -168,9 +168,9 @@ static bool node_tab_close(Ted *ted, Node *node, u16 index) { if (index < node->active_tab) --node->active_tab; node->active_tab = clamp_u16(node->active_tab, 0, ntabs - 1); - if (ted->active_node == node) { + if (was_active) { // fix active buffer if necessary - ted->active_buffer = &ted->buffers[node->tabs[node->active_tab]]; + ted_switch_to_buffer(ted, &ted->buffers[node->tabs[node->active_tab]]); } return true; } |