summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--buffer.c4
-rw-r--r--command.c5
-rw-r--r--command.h6
-rw-r--r--menu.c59
-rw-r--r--ted.cfg3
-rw-r--r--ted.h1
6 files changed, 69 insertions, 9 deletions
diff --git a/buffer.c b/buffer.c
index 378d5c7..57325b8 100644
--- a/buffer.c
+++ b/buffer.c
@@ -863,6 +863,10 @@ void buffer_scroll_to_pos(TextBuffer *buffer, BufferPos pos) {
buffer_correct_scroll(buffer); // it's possible that min/max_scroll_x/y go too far
}
+// scroll in such a way that this position is in the center of the screen
+void buffer_scroll_center_pos(TextBuffer *buffer) {
+}
+
// if the cursor is offscreen, this will scroll to make it onscreen.
void buffer_scroll_to_cursor(TextBuffer *buffer) {
buffer_scroll_to_pos(buffer, buffer->cursor_pos);
diff --git a/command.c b/command.c
index 4488289..37ec84a 100644
--- a/command.c
+++ b/command.c
@@ -301,8 +301,11 @@ void command_execute(Ted *ted, Command c, i64 argument) {
case CMD_BUILD_PREV_ERROR:
build_prev_error(ted);
break;
- case CMD_OPEN_DEFINITION_MENU:
+ case CMD_GOTO_DEFINITION:
menu_open(ted, MENU_GOTO_DEFINITION);
break;
+ case CMD_GOTO_LINE:
+ menu_open(ted, MENU_GOTO_LINE);
+ break;
}
}
diff --git a/command.h b/command.h
index 8f61424..9824fbf 100644
--- a/command.h
+++ b/command.h
@@ -69,7 +69,8 @@ ENUM_U16 {
CMD_BUILD_PREV_ERROR,
CMD_BUILD_NEXT_ERROR,
- CMD_OPEN_DEFINITION_MENU, // "go to definition of..."
+ CMD_GOTO_DEFINITION, // "go to definition of..."
+ CMD_GOTO_LINE, // open "goto line..." menu
CMD_ESCAPE, // by default this is the escape key. closes menus, etc.
@@ -137,7 +138,8 @@ static CommandName const command_names[CMD_COUNT] = {
{"build", CMD_BUILD},
{"build-prev-error", CMD_BUILD_PREV_ERROR},
{"build-next-error", CMD_BUILD_NEXT_ERROR},
- {"open-definition-menu", CMD_OPEN_DEFINITION_MENU},
+ {"goto-definition", CMD_GOTO_DEFINITION},
+ {"goto-line", CMD_GOTO_LINE},
{"escape", CMD_ESCAPE},
};
diff --git a/menu.c b/menu.c
index 284b0e9..fb9eb56 100644
--- a/menu.c
+++ b/menu.c
@@ -4,6 +4,7 @@ static void menu_open(Ted *ted, Menu menu) {
ted->prev_active_buffer = ted->active_buffer;
ted->active_buffer = NULL;
*ted->warn_overwrite = 0; // clear warn_overwrite
+ buffer_clear(&ted->line_buffer);
switch (menu) {
case MENU_NONE: assert(0); break;
case MENU_OPEN:
@@ -23,6 +24,9 @@ static void menu_open(Ted *ted, Menu menu) {
case MENU_GOTO_DEFINITION:
tag_selector_open(ted);
break;
+ case MENU_GOTO_LINE:
+ ted->active_buffer = &ted->line_buffer;
+ break;
}
}
@@ -196,6 +200,28 @@ static void menu_update(Ted *ted) {
free(chosen_tag);
}
} break;
+ case MENU_GOTO_LINE: {
+ TextBuffer *line_buffer = &ted->line_buffer;
+ char *contents = str32_to_utf8_cstr(buffer_get_line(line_buffer, 0));
+ char *end;
+ long line_number = strtol(contents, &end, 0);
+ TextBuffer *buffer = ted->prev_active_buffer;
+ if (line_number > 0 && *end == '\0' && line_number <= (long)buffer->nlines) {
+ if (line_buffer->line_buffer_submitted) {
+ // let's go there!
+ BufferPos pos = {line_number - 1, 0};
+
+ menu_close(ted);
+ buffer_cursor_move_to_pos(buffer, pos);
+ buffer_center_cursor(buffer);
+ } else {
+ // scroll to the line
+
+ }
+ }
+ line_buffer->line_buffer_submitted = false;
+ free(contents);
+ } break;
}
}
@@ -205,7 +231,8 @@ static void menu_render(Ted *ted) {
Settings const *settings = &ted->settings;
u32 const *colors = settings->colors;
float window_width = ted->window_width, window_height = ted->window_height;
- Font *font_bold = ted->font_bold;
+ Font *font_bold = ted->font_bold, *font = ted->font;
+ float char_height = text_font_char_height(font);
float char_height_bold = text_font_char_height(font_bold);
// render backdrop
@@ -224,14 +251,14 @@ static void menu_render(Ted *ted) {
float padding = settings->padding;
- Rect rect = menu_rect(ted);
+ Rect bounds = menu_rect(ted);
float menu_x1, menu_y1, menu_x2, menu_y2;
- rect_coords(rect, &menu_x1, &menu_y1, &menu_x2, &menu_y2);
+ rect_coords(bounds, &menu_x1, &menu_y1, &menu_x2, &menu_y2);
if (menu == MENU_OPEN || menu == MENU_SAVE_AS || menu == MENU_GOTO_DEFINITION) {
// menu rectangle & border
- gl_geometry_rect(rect, colors[COLOR_MENU_BG]);
- gl_geometry_rect_border(rect, settings->border_thickness, colors[COLOR_BORDER]);
+ gl_geometry_rect(bounds, colors[COLOR_MENU_BG]);
+ gl_geometry_rect_border(bounds, settings->border_thickness, colors[COLOR_BORDER]);
gl_geometry_draw();
menu_x1 += padding;
@@ -274,5 +301,27 @@ static void menu_render(Ted *ted) {
case MENU_GOTO_DEFINITION: {
tag_selector_render(ted, rect4(menu_x1, menu_y1, menu_x2, menu_y2));
} break;
+ case MENU_GOTO_LINE: {
+ float menu_height = char_height + 2 * padding;
+ Rect r = rect(V2(padding, window_height - menu_height - padding), V2(window_width - 2 * padding, menu_height));
+ gl_geometry_rect(r, colors[COLOR_MENU_BG]);
+ gl_geometry_rect_border(r, settings->border_thickness, colors[COLOR_BORDER]);
+ char const *text = "Go to line...";
+ v2 text_size = text_get_size_v2(font_bold, text);
+ float x1, y1, x2, y2;
+ rect_coords(r, &x1, &y1, &x2, &y2);
+ x1 += padding;
+ y1 += padding;
+ x2 -= padding;
+ y2 -= padding;
+ // render "Go to line" text
+ text_utf8(font_bold, text, x1, 0.5f * (y1 + y2 - text_size.y), colors[COLOR_TEXT]);
+ x1 += text_size.x + padding;
+ gl_geometry_draw();
+ text_render(font_bold);
+
+ // line buffer
+ buffer_render(&ted->line_buffer, rect4(x1, y1, x2, y2));
+ } break;
}
}
diff --git a/ted.cfg b/ted.cfg
index e66c93e..043f55c 100644
--- a/ted.cfg
+++ b/ted.cfg
@@ -118,7 +118,8 @@ F4 = :build
Ctrl+[ = :build-prev-error
Ctrl+] = :build-next-error
-Ctrl+d = :open-definition-menu
+Ctrl+d = :goto-definition
+Ctrl+g = :goto-line
Escape = :escape
diff --git a/ted.h b/ted.h
index 0b7445b..2ca308f 100644
--- a/ted.h
+++ b/ted.h
@@ -167,6 +167,7 @@ ENUM_U16 {
MENU_WARN_UNSAVED, // warn about unsaved changes
MENU_ASK_RELOAD, // prompt about whether to reload file which has ben changed by another program
MENU_GOTO_DEFINITION,
+ MENU_GOTO_LINE,
} ENUM_U16_END(Menu);
typedef struct {