From 966197c46b09539c410c8e9c04e83dfc41a796a6 Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Mon, 1 Mar 2021 20:15:33 -0500 Subject: fix active_node after tab close --- node.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/node.c b/node.c index be92638..4f06bce 100644 --- a/node.c +++ b/node.c @@ -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; } -- cgit v1.2.3