summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2021-02-24 11:48:54 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2021-02-24 11:48:54 -0500
commit94e09c98f3dbef3c041750cc019efbc29e9254e6 (patch)
tree50bc0bb82825eb495dbebc92478412972da78c45
parent4aa02183b7f317ca1183b4d3e58ec9da166479d6 (diff)
start split
-rw-r--r--colors.h2
-rw-r--r--command.c22
-rw-r--r--main.c8
-rw-r--r--node.c14
-rw-r--r--ted.cfg2
5 files changed, 33 insertions, 15 deletions
diff --git a/colors.h b/colors.h
index a5139c7..e1f033c 100644
--- a/colors.h
+++ b/colors.h
@@ -21,6 +21,7 @@ ENUM_U16 {
COLOR_ERROR_BG,
COLOR_ERROR_BORDER,
COLOR_ACTIVE_TAB_HL,
+ COLOR_SELECTED_TAB_HL,
COLOR_FIND_HL,
COLOR_YES,
@@ -70,6 +71,7 @@ static ColorName const color_names[COLOR_COUNT] = {
{COLOR_ERROR_BG, "error-bg"},
{COLOR_ERROR_BORDER, "error-border"},
{COLOR_ACTIVE_TAB_HL, "active-tab-hl"},
+ {COLOR_SELECTED_TAB_HL, "selected-tab-hl"},
{COLOR_FIND_HL, "find-hl"},
{COLOR_KEYWORD, "keyword"},
{COLOR_BUILTIN, "builtin"},
diff --git a/command.c b/command.c
index fd6334c..e9ffd75 100644
--- a/command.c
+++ b/command.c
@@ -310,20 +310,32 @@ void command_execute(Ted *ted, Command c, i64 argument) {
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) {
+ if (left_idx >= 0 && right_idx >= 0) {
Node *left = &ted->nodes[left_idx];
Node *right = &ted->nodes[right_idx];
- arr_add(right->tabs, )
+ u16 active_tab = node->active_tab;
+ // put active tab on the right
+ arr_add(right->tabs, node->tabs[active_tab]);
+ for (u32 i = 0; i < arr_len(node->tabs); ++i) {
+ if (i != active_tab) {
+ // put all other tabs on the left
+ arr_add(left->tabs, node->tabs[i]);
+ }
+ }
+
+ arr_clear(node->tabs);
+ node->split_a = (u16)left_idx;
+ node->split_b = (u16)right_idx;
+ node->split_vertical = c == CMD_SPLIT_VERTICAL;
+ node->split_pos = 0.5f;
+ ted->active_node = &ted->nodes[right_idx];
}
}
}
- #endif
break;
}
}
diff --git a/main.c b/main.c
index 58a98b0..76b17a7 100644
--- a/main.c
+++ b/main.c
@@ -1,5 +1,7 @@
// @TODO:
-// - split
+// - get ctrl+w to work properly
+// - split depth limit
+// - resize split (i.e. change split_pos)
// - Windows installation
// - on crash, output backtrace to log
@@ -437,8 +439,10 @@ int main(int argc, char **argv) {
BufferPos buffer_pos;
if (buffer_pixels_to_pos(buffer, pos, &buffer_pos)) {
// user clicked on buffer
- if (!ted->menu)
+ if (!ted->menu) {
ted->active_buffer = buffer;
+ ted->active_node = node;
+ }
if (buffer == ted->active_buffer) {
add = false;
switch (ted->key_modifier) {
diff --git a/node.c b/node.c
index d9e04a1..f30cb42 100644
--- a/node.c
+++ b/node.c
@@ -101,7 +101,9 @@ static void node_frame(Ted *ted, Node *node, Rect r) {
for (u16 c = 0; c < ted->nmouse_clicks[SDL_BUTTON_LEFT]; ++c) {
v2 click = ted->mouse_clicks[SDL_BUTTON_LEFT][c];
if (rect_contains_point(tab_bar_rect, click)) {
+ // click on tab to switch to it
u16 tab_index = (u16)((click.x - r.pos.x) / tab_width);
+ ted->active_node = node;
node_switch_to_tab(ted, node, tab_index);
}
}
@@ -156,7 +158,7 @@ static void node_frame(Ted *ted, Node *node, Rect r) {
if (i == node->active_tab) {
// highlight active tab
- gl_geometry_rect(tab_rect, colors[is_active ? COLOR_ACTIVE_TAB_HL : COLOR_HL]);
+ gl_geometry_rect(tab_rect, colors[is_active ? COLOR_ACTIVE_TAB_HL : COLOR_SELECTED_TAB_HL]);
// set window title to active tab's title
strbuf_printf(ted->window_title, "ted %s", tab_title);
}
@@ -173,14 +175,11 @@ static void node_frame(Ted *ted, Node *node, Rect r) {
buffer_rect.size.y -= tab_bar_height;
buffer_render(buffer, buffer_rect);
} else {
-
-#if 0
- // @TODO: test this
// this node is a split
Node *a = &ted->nodes[node->split_a];
Node *b = &ted->nodes[node->split_b];
Rect r1 = r, r2 = r;
- if (node->vertical_split) {
+ if (node->split_vertical) {
float split_pos = r.size.y * node->split_pos;
r1.size.y = split_pos;
r2.pos.y += split_pos;
@@ -191,9 +190,8 @@ static void node_frame(Ted *ted, Node *node, Rect r) {
r2.pos.x += split_pos;
r2.size.x = r.size.x - split_pos;
}
- node_render(ted, a, r1);
- node_render(ted, b, r2);
-#endif
+ node_frame(ted, a, r1);
+ node_frame(ted, b, r2);
}
}
diff --git a/ted.cfg b/ted.cfg
index dd3c365..da4a1a3 100644
--- a/ted.cfg
+++ b/ted.cfg
@@ -129,6 +129,8 @@ Escape = :escape
[colors]
border = #a77
active-tab-hl = #a77a
+# this color is used for tabs which are selected, but not active (because you are on the other side of a split, perhaps)
+selected-tab-hl = #7777
cursor-line-bg = #222
cursor = #3ff
# color to highlight matching brackets with