diff options
author | pommicket <pommicket@gmail.com> | 2022-03-26 15:50:07 -0400 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2022-03-26 15:50:07 -0400 |
commit | 6617f77adbaeb0dc79c7b07f6ec3a107adb117db (patch) | |
tree | d35c0cea859ff0c3fe0bf178111a0abd59ef9ce2 | |
parent | 53ce10723f8d683dda4194fc969b4a8500b76b19 (diff) |
fixed ctrl+w behavior with find/build
-rw-r--r-- | build.c | 4 | ||||
-rw-r--r-- | command.c | 36 | ||||
-rw-r--r-- | ted.c | 13 |
3 files changed, 38 insertions, 15 deletions
@@ -12,6 +12,10 @@ static void build_stop(Ted *ted) { free(*cmd); } arr_clear(ted->build_queue); + if (ted->active_buffer == &ted->build_buffer) { + ted->active_buffer = NULL; + ted_reset_active_buffer(ted); + } } // call before adding anything to the build queue @@ -301,23 +301,29 @@ void command_execute(Ted *ted, Command c, i64 argument) { case CMD_TAB_CLOSE: { if (ted->menu) { menu_close(ted); - } else { - if (node) { - u16 tab_idx = node->active_tab; - buffer = &ted->buffers[node->tabs[tab_idx]]; - // (an argument of 2 overrides the unsaved changes dialog) - if (argument != 2 && buffer_unsaved_changes(buffer)) { - // there are unsaved changes! - ted->warn_unsaved = CMD_TAB_CLOSE; - strbuf_printf(ted->warn_unsaved_names, "%s", path_filename(buffer->filename)); - menu_open(ted, MENU_WARN_UNSAVED); - } else { - node_tab_close(ted, node, node->active_tab); - } + } else if (ted->find) { + find_close(ted); + } else if (node) { + u16 tab_idx = node->active_tab; + buffer = &ted->buffers[node->tabs[tab_idx]]; + // (an argument of 2 overrides the unsaved changes dialog) + if (argument != 2 && buffer_unsaved_changes(buffer)) { + // there are unsaved changes! + ted->warn_unsaved = CMD_TAB_CLOSE; + strbuf_printf(ted->warn_unsaved_names, "%s", path_filename(buffer->filename)); + menu_open(ted, MENU_WARN_UNSAVED); } else { - command_execute(ted, CMD_QUIT, 1); - return; + node_tab_close(ted, node, node->active_tab); } + } else if (ted->build_shown) { + build_stop(ted); + } else if (ted->nodes_used[0]) { + // there are nodes open, but no active node. + // do nothing. + } else { + // no nodes open + command_execute(ted, CMD_QUIT, 1); + return; } } break; case CMD_TAB_NEXT: @@ -139,6 +139,19 @@ void ted_switch_to_buffer(Ted *ted, TextBuffer *buffer) { } } +// set ted->active_buffer to something nice +static void ted_reset_active_buffer(Ted *ted) { + if (ted->nodes_used[0]) { + Node *node = &ted->nodes[0]; + while (!node->tabs) + node = &ted->nodes[node->split_a]; // arbitrarily pick split_a. + ted_switch_to_buffer(ted, &ted->buffers[node->tabs[node->active_tab]]); + } else { + // there's nothing to set it to + ted->active_buffer = NULL; + } +} + // returns the index of an available buffer, or -1 if none are available static i32 ted_new_buffer(Ted *ted) { |