summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--command.c20
-rw-r--r--command.h5
-rw-r--r--main.c3
-rw-r--r--menu.c9
-rw-r--r--node.c5
-rw-r--r--ted.cfg3
-rw-r--r--ted.h4
7 files changed, 39 insertions, 10 deletions
diff --git a/command.c b/command.c
index 37ec84a..fd6334c 100644
--- a/command.c
+++ b/command.c
@@ -19,6 +19,7 @@ char const *command_to_str(Command c) {
void command_execute(Ted *ted, Command c, i64 argument) {
TextBuffer *buffer = ted->active_buffer;
+ Node *node = ted->active_node;
Settings *settings = &ted->settings;
@@ -239,7 +240,6 @@ void command_execute(Ted *ted, Command c, i64 argument) {
if (ted->menu) {
menu_close(ted);
} else {
- Node *node = ted->active_node;
if (node) {
u16 tab_idx = node->active_tab;
buffer = &ted->buffers[node->tabs[tab_idx]];
@@ -307,5 +307,23 @@ void command_execute(Ted *ted, Command c, i64 argument) {
case CMD_GOTO_LINE:
menu_open(ted, MENU_GOTO_LINE);
break;
+
+ case CMD_SPLIT_HORIZONTAL:
+ case CMD_SPLIT_VERTICAL:
+
+#if 0
+ if (node) {
+ if (arr_len(node->tabs) > 1) { // need at least 2 tabs to split
+ i32 left_idx = ted_new_node(ted);
+ i32 right_idx = ted_new_node(ted);
+ if (left >= 0 && right >= 0) {
+ Node *left = &ted->nodes[left_idx];
+ Node *right = &ted->nodes[right_idx];
+ arr_add(right->tabs, )
+ }
+ }
+ }
+ #endif
+ break;
}
}
diff --git a/command.h b/command.h
index 9824fbf..a74f42a 100644
--- a/command.h
+++ b/command.h
@@ -71,6 +71,9 @@ ENUM_U16 {
CMD_GOTO_DEFINITION, // "go to definition of..."
CMD_GOTO_LINE, // open "goto line..." menu
+
+ CMD_SPLIT_HORIZONTAL,
+ CMD_SPLIT_VERTICAL,
CMD_ESCAPE, // by default this is the escape key. closes menus, etc.
@@ -140,6 +143,8 @@ static CommandName const command_names[CMD_COUNT] = {
{"build-next-error", CMD_BUILD_NEXT_ERROR},
{"goto-definition", CMD_GOTO_DEFINITION},
{"goto-line", CMD_GOTO_LINE},
+ {"split-horizontal", CMD_SPLIT_HORIZONTAL},
+ {"split-vertical", CMD_SPLIT_VERTICAL},
{"escape", CMD_ESCAPE},
};
diff --git a/main.c b/main.c
index 3063ffe..58a98b0 100644
--- a/main.c
+++ b/main.c
@@ -1,7 +1,4 @@
// @TODO:
-// - :run -- if .html file, open in browser, otherwise figure out a way of sending a command to shell
-// running in terminal emulator?? (don't want to implement stdin/ANSI codes/etc.)
-
// - split
// - Windows installation
diff --git a/menu.c b/menu.c
index c0ff5f4..89fafd0 100644
--- a/menu.c
+++ b/menu.c
@@ -2,7 +2,8 @@ static void menu_open(Ted *ted, Menu menu) {
if (ted->find) find_close(ted);
ted->menu = menu;
TextBuffer *prev_buf = ted->prev_active_buffer = ted->active_buffer;
- ted->prev_active_buffer_scroll = V2D(prev_buf->scroll_x, prev_buf->scroll_y);
+ if (prev_buf)
+ ted->prev_active_buffer_scroll = V2D(prev_buf->scroll_x, prev_buf->scroll_y);
ted->active_buffer = NULL;
*ted->warn_overwrite = 0; // clear warn_overwrite
@@ -35,8 +36,10 @@ static void menu_open(Ted *ted, Menu menu) {
static void menu_close(Ted *ted) {
TextBuffer *buffer = ted->active_buffer = ted->prev_active_buffer;
ted->prev_active_buffer = NULL;
- buffer->scroll_x = ted->prev_active_buffer_scroll.x;
- buffer->scroll_y = ted->prev_active_buffer_scroll.y;
+ if (buffer) {
+ buffer->scroll_x = ted->prev_active_buffer_scroll.x;
+ buffer->scroll_y = ted->prev_active_buffer_scroll.y;
+ }
switch (ted->menu) {
case MENU_NONE: assert(0); break;
case MENU_OPEN:
diff --git a/node.c b/node.c
index 7ca4843..d9e04a1 100644
--- a/node.c
+++ b/node.c
@@ -69,7 +69,9 @@ static bool node_tab_close(Ted *ted, Node *node, u16 index) {
ntabs = (u16)arr_len(node->tabs); // update ntabs
assert(ntabs);
- // make sure active tab is valid
+ // fix active_tab
+ if (index < node->active_tab)
+ --node->active_tab;
node->active_tab = clamp_u16(node->active_tab, 0, ntabs - 1);
if (ted->active_node == node) {
// fix active buffer if necessary
@@ -104,6 +106,7 @@ static void node_frame(Ted *ted, Node *node, Rect r) {
}
}
for (u16 c = 0; c < ted->nmouse_clicks[SDL_BUTTON_MIDDLE]; ++c) {
+ // middle-click to close tab
v2 click = ted->mouse_clicks[SDL_BUTTON_MIDDLE][c];
if (rect_contains_point(tab_bar_rect, click)) {
u16 tab_index = (u16)((click.x - r.pos.x) / tab_width);
diff --git a/ted.cfg b/ted.cfg
index 043f55c..dd3c365 100644
--- a/ted.cfg
+++ b/ted.cfg
@@ -121,6 +121,9 @@ Ctrl+] = :build-next-error
Ctrl+d = :goto-definition
Ctrl+g = :goto-line
+Ctrl+/ = :split-horizontal
+Ctrl+Shift+/ = :split-vertical
+
Escape = :escape
[colors]
diff --git a/ted.h b/ted.h
index d629dd5..9f6c582 100644
--- a/ted.h
+++ b/ted.h
@@ -204,8 +204,8 @@ typedef struct {
typedef struct Node {
u16 *tabs; // dynamic array of indices into ted->buffers, or NULL if this is a split
float split_pos; // number from 0 to 1 indicating where the split is.
- u16 active_tab;
- bool vertical_split; // is the split vertical? if false, this split looks like a|b
+ u16 active_tab; // index of active tab in tabs.
+ bool split_vertical; // is the split vertical? if false, this split looks like a|b
u16 split_a; // split left/upper half; index into ted->nodes
u16 split_b; // split right/lower half
} Node;