Skip to content

Commit

Permalink
fix node bug
Browse files Browse the repository at this point in the history
  • Loading branch information
pommicket committed Aug 15, 2023
1 parent 8784577 commit da57a47
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 25 deletions.
34 changes: 13 additions & 21 deletions node.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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;
Expand Down
9 changes: 8 additions & 1 deletion ted.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,9 @@ static Node *ted_buffer_location_in_node_tree(Ted *ted, TextBuffer *buffer, u16
}

void ted_switch_to_buffer(Ted *ted, TextBuffer *buffer) {
if (buffer == ted->active_buffer)
return;

TextBuffer *search_buffer = find_search_buffer(ted);
ted->active_buffer = buffer;
autocomplete_close(ted);
Expand Down Expand Up @@ -516,6 +519,7 @@ void ted_node_switch(Ted *ted, Node *node) {
while (node_child1(node)) {
node = node_child1(node);
}
ted->active_node = node;
ted_switch_to_buffer(ted, node_get_tab(node, node_active_tab(node)));
}

Expand All @@ -527,7 +531,7 @@ static TextBuffer *ted_open_buffer(Ted *ted, u16 *tab) {
if (!node) {
if (!arr_len(ted->nodes)) {
// no nodes open; create a root node
node = ted->active_node = node_new(ted);
node = node_new(ted);
} else if (ted->prev_active_buffer) {
// opening a file while a menu is open
// it may happen.... (currently happens for rename symbol)
Expand All @@ -548,6 +552,9 @@ static TextBuffer *ted_open_buffer(Ted *ted, u16 *tab) {
u16 active_tab = (u16)(node_tab_count(node) - 1);
*tab = active_tab;
node_tab_switch(ted, node, active_tab);
ted->active_node = node;
ted->active_buffer = new_buffer;

return new_buffer;
}

Expand Down
6 changes: 3 additions & 3 deletions windows_installer/ted/ted.vdproj
Original file line number Diff line number Diff line change
Expand Up @@ -620,15 +620,15 @@
{
"Name" = "8:Microsoft Visual Studio"
"ProductName" = "8:ted"
"ProductCode" = "8:{1065E316-820C-40EF-BE72-CCE18D421950}"
"PackageCode" = "8:{14783293-5226-470A-A899-DEEC573CD8E6}"
"ProductCode" = "8:{51C543F8-F64F-4D57-ADAF-B7FF69EA8D1D}"
"PackageCode" = "8:{2553F30D-B299-4352-8C82-61883B4BE646}"
"UpgradeCode" = "8:{844F6C2B-DF3B-4A81-9BD5-603401BBA651}"
"AspNetVersion" = "8:2.0.50727.0"
"RestartWWWService" = "11:FALSE"
"RemovePreviousVersions" = "11:TRUE"
"DetectNewerInstalledVersion" = "11:FALSE"
"InstallAllUsers" = "11:FALSE"
"ProductVersion" = "8:23.08.0110"
"ProductVersion" = "8:23.08.1517"
"Manufacturer" = "8:ted"
"ARPHELPTELEPHONE" = "8:"
"ARPHELPLINK" = "8:"
Expand Down

0 comments on commit da57a47

Please sign in to comment.