diff options
-rw-r--r-- | base.h | 6 | ||||
-rw-r--r-- | command.c | 3 | ||||
-rw-r--r-- | command.h | 8 | ||||
-rw-r--r-- | main.c | 1 | ||||
-rw-r--r-- | node.c | 19 | ||||
-rw-r--r-- | ted.c | 8 | ||||
-rw-r--r-- | ted.cfg | 1 |
7 files changed, 40 insertions, 6 deletions
@@ -32,6 +32,12 @@ #include <assert.h> #include <uchar.h> +#if !__TINYC__ && __STDC_VERSION__ >= 201112 +#define static_assert_if_possible(cond) _Static_assert(cond, "Static assertion failed"); +#else +#define static_assert_if_possible(cond) +#endif + typedef uint8_t u8; typedef uint16_t u16; typedef uint32_t u32; @@ -317,5 +317,8 @@ void command_execute(Ted *ted, Command c, i64 argument) { case CMD_SPLIT_JOIN: node_join(ted, node); break; + case CMD_SPLIT_SWAP: + node_split_swap(ted); + break; } } @@ -75,7 +75,8 @@ ENUM_U16 { CMD_SPLIT_HORIZONTAL, CMD_SPLIT_VERTICAL, CMD_SPLIT_JOIN, - + CMD_SPLIT_SWAP, // go to the other side of a split + CMD_ESCAPE, // by default this is the escape key. closes menus, etc. CMD_COUNT @@ -85,7 +86,7 @@ typedef struct { char const *name; Command cmd; } CommandName; -static CommandName const command_names[CMD_COUNT] = { +static CommandName const command_names[] = { {"unknown", CMD_UNKNOWN}, {"noop", CMD_NOOP}, {"left", CMD_LEFT}, @@ -147,6 +148,9 @@ static CommandName const command_names[CMD_COUNT] = { {"split-horizontal", CMD_SPLIT_HORIZONTAL}, {"split-vertical", CMD_SPLIT_VERTICAL}, {"split-join", CMD_SPLIT_JOIN}, + {"split-swap", CMD_SPLIT_SWAP}, {"escape", CMD_ESCAPE}, }; +static_assert_if_possible(arr_count(command_names) == CMD_COUNT) + @@ -1,5 +1,4 @@ // @TODO: -// - :split-swap // - fix: ctrl+f something, then switch to another tab (hl rects still showing up) // - Windows installation @@ -137,8 +137,7 @@ static void node_close(Ted *ted, u16 node_idx) { // make sure we don't set the active node to a split while (!new_active_node->tabs) new_active_node = &ted->nodes[new_active_node->split_a]; - ted->active_node = new_active_node; - ted->active_buffer = &ted->buffers[ted->active_node->tabs[ted->active_node->active_tab]]; + ted_node_switch(ted, new_active_node); } } } @@ -390,7 +389,21 @@ static void node_split(Ted *ted, Node *node, bool vertical) { node->split_vertical = vertical; node->split_pos = 0.5f; if (node == ted->active_node) - ted->active_node = &ted->nodes[right_idx]; + ted_node_switch(ted, &ted->nodes[right_idx]); + } + } +} + +// swap to the other side of a split +static void node_split_swap(Ted *ted) { + assert(ted->active_node); + u16 active_node_idx = (u16)(ted->active_node - ted->nodes); + Node *parent = &ted->nodes[node_parent(ted, active_node_idx)]; + if (parent) { + if (parent->split_a == active_node_idx) { + ted_node_switch(ted, &ted->nodes[parent->split_b]); + } else { + ted_node_switch(ted, &ted->nodes[parent->split_a]); } } } @@ -130,6 +130,13 @@ static i32 ted_new_node(Ted *ted) { } +// switch to this node +static void ted_node_switch(Ted *ted, Node *node) { + ted->active_node = node; + assert(node->tabs); + ted->active_buffer = &ted->buffers[node->tabs[node->active_tab]]; +} + static bool node_tab_close(Ted *ted, Node *node, u16 index); // Open a new buffer. Fills out *tab to the index of the tab used, and *buffer_idx to the index of the buffer. @@ -187,6 +194,7 @@ static void ted_switch_to_buffer(Ted *ted, u16 buffer_idx) { assert(0); } + // Returns true on success static bool ted_open_file(Ted *ted, char const *filename) { // first, check if file is already open @@ -125,6 +125,7 @@ Ctrl+/ = :split-horizontal Ctrl+Shift+/ = :split-vertical # unsplit Ctrl+j = :split-join +Ctrl+tab = :split-swap Escape = :escape |