diff options
-rw-r--r-- | buffer.c | 10 | ||||
-rw-r--r-- | main.c | 2 | ||||
-rw-r--r-- | math.c | 10 | ||||
-rw-r--r-- | menu.c | 14 | ||||
-rw-r--r-- | ted.h | 3 |
5 files changed, 31 insertions, 8 deletions
@@ -864,7 +864,15 @@ void buffer_scroll_to_pos(TextBuffer *buffer, BufferPos pos) { } // scroll in such a way that this position is in the center of the screen -void buffer_scroll_center_pos(TextBuffer *buffer) { +void buffer_scroll_center_pos(TextBuffer *buffer, BufferPos pos) { + double line = pos.line; + double col = buffer_index_to_column(buffer, pos.line, pos.index); + + double display_lines = buffer_display_lines(buffer); + double display_cols = buffer_display_cols(buffer); + buffer->scroll_x = col - display_cols * 0.5; + buffer->scroll_y = line - display_lines * 0.5; + buffer_correct_scroll(buffer); } // if the cursor is offscreen, this will scroll to make it onscreen. @@ -1,6 +1,4 @@ // @TODO: -// - goto line - // - :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.) @@ -456,6 +456,16 @@ static void v4_print(v4 v) { printf("(%f, %f, %f, %f)\n", v.x, v.y, v.z, v.w); } +typedef struct { + double x, y; +} v2d; + +static v2d V2D(double x, double y) { + v2d v; + v.x = x; + v.y = y; + return v; +} // matrices are column-major, because that's what they are in OpenGL typedef struct { @@ -1,7 +1,9 @@ static void menu_open(Ted *ted, Menu menu) { if (ted->find) find_close(ted); ted->menu = menu; - ted->prev_active_buffer = ted->active_buffer; + TextBuffer *prev_buf = ted->prev_active_buffer = ted->active_buffer; + 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 buffer_clear(&ted->line_buffer); @@ -31,8 +33,10 @@ static void menu_open(Ted *ted, Menu menu) { } static void menu_close(Ted *ted) { - ted->active_buffer = ted->prev_active_buffer; + 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; switch (ted->menu) { case MENU_NONE: assert(0); break; case MENU_OPEN: @@ -207,16 +211,16 @@ static void menu_update(Ted *ted) { long line_number = strtol(contents, &end, 0); TextBuffer *buffer = ted->prev_active_buffer; if (line_number > 0 && *end == '\0' && line_number <= (long)buffer->nlines) { + BufferPos pos = {line_number - 1, 0}; + 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 - + buffer_scroll_center_pos(buffer, pos); } } line_buffer->line_buffer_submitted = false; @@ -272,6 +272,9 @@ typedef struct Ted { BuildError *build_errors; // dynamic array of build errors u32 build_error; // build error we are currently "on" + + // used by menus to keep track of the scroll position so we can return to it. + v2d prev_active_buffer_scroll; char **tag_selector_entries; // an array of all tags (see tag_selector_open) |