diff options
-rw-r--r-- | main.c | 3 | ||||
-rw-r--r-- | ted-base.c | 18 | ||||
-rw-r--r-- | ted.h | 3 |
3 files changed, 17 insertions, 7 deletions
@@ -464,7 +464,8 @@ int main(int argc, char **argv) { { float x1 = 50, y1 = 50, x2 = window_width-50, y2 = window_height-50; - buffer_render(&ted->buffers[ted->active_node->tabs[0]], x1, y1, x2, y2); + Node *node = ted->active_node; + buffer_render(&ted->buffers[node->tabs[node->active_tab]], x1, y1, x2, y2); if (text_has_err()) { ted_seterr(ted, "Couldn't render text: %s", text_get_err()); } @@ -95,6 +95,7 @@ static i32 ted_new_buffer(Ted *ted) { for (i32 i = 0; i < TED_MAX_BUFFERS; ++i) { if (!buffers_used[i]) { buffers_used[i] = true; + buffer_create(&ted->buffers[i], ted); return i; } } @@ -125,14 +126,19 @@ static WarnUnusedResult TextBuffer *ted_open_file(Ted *ted, char const *filename ted_seterr(ted, "Too many buffers open!"); return NULL; } else { - arr_add(ted->active_node->tabs, (u16)new_buffer_index); - TextBuffer *new_buffer = &ted->buffers[new_buffer_index]; - if (buffer_load_file(new_buffer, filename)) { - ted->active_buffer = new_buffer; - return new_buffer; + Node *node = ted->active_node; + if (arr_len(node->tabs) < TED_MAX_TABS) { + arr_add(node->tabs, (u16)new_buffer_index); + TextBuffer *new_buffer = &ted->buffers[new_buffer_index]; + if (node->tabs && buffer_load_file(new_buffer, filename)) { + ted->active_buffer = new_buffer; + node->active_tab = (u16)(arr_len(node->tabs) - 1); + return new_buffer; + } } else { - return NULL; + ted_seterr(ted, "Too many tabs."); } + return NULL; } } @@ -103,12 +103,15 @@ typedef struct { // a node is a collection of tabs OR a split of two nodes typedef struct Node { u16 *tabs; // dynamic array of indices into ted->buffers, or NULL if this is a split + u16 active_tab; u16 left; // index into ted->nodes u16 right; } Node; #define TED_MAX_BUFFERS 256 #define TED_MAX_NODES 256 +// max tabs per node +#define TED_MAX_TABS 100 typedef struct Ted { Font *font_bold; Font *font; |