diff options
author | pommicket <pommicket@gmail.com> | 2023-03-02 10:52:08 -0500 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2023-03-02 10:52:08 -0500 |
commit | 4aebef26deaed5d26fe450193da044f7734051e1 (patch) | |
tree | 1bc66ba0db2e41bb78241eda9bf14466e8538f37 | |
parent | eddcc7e8c6c02970ac658024b3a8c6b5f416c8a5 (diff) |
:previous-position
-rw-r--r-- | buffer.c | 10 | ||||
-rw-r--r-- | command.c | 4 | ||||
-rw-r--r-- | command.h | 1 | ||||
-rw-r--r-- | main.c | 1 | ||||
-rw-r--r-- | ted.cfg | 2 | ||||
-rw-r--r-- | ted.h | 4 |
6 files changed, 21 insertions, 1 deletions
@@ -1119,12 +1119,22 @@ void buffer_cursor_move_to_pos(TextBuffer *buffer, BufferPos pos) { if (buffer_pos_eq(buffer->cursor_pos, pos)) { return; } + + if (labs((long)buffer->cursor_pos.line - (long)pos.line) > 20) { + // if this is a big jump, update the previous cursor pos + buffer->prev_cursor_pos = buffer->cursor_pos; + } + buffer->cursor_pos = pos; buffer->selection = false; buffer_scroll_to_cursor(buffer); signature_help_retrigger(buffer->ted); } +void buffer_cursor_move_to_prev_pos(TextBuffer *buffer) { + buffer_cursor_move_to_pos(buffer, buffer->prev_cursor_pos); +} + i64 buffer_cursor_move_left(TextBuffer *buffer, i64 by) { BufferPos cur_pos = buffer->cursor_pos; i64 ret = 0; @@ -39,6 +39,7 @@ static CommandName command_names[] = { {"select-down-blank-line", CMD_SELECT_DOWN_BLANK_LINE}, {"page-up", CMD_PAGE_UP}, {"page-down", CMD_PAGE_DOWN}, + {"previous-position", CMD_PREVIOUS_POSITION}, {"tab", CMD_TAB}, {"backtab", CMD_BACKTAB}, {"insert-text", CMD_INSERT_TEXT}, @@ -265,6 +266,9 @@ void command_execute(Ted *ted, Command c, i64 argument) { if (buffer) buffer_select_down_blank_lines(buffer, argument); autocomplete_close(ted); break; + case CMD_PREVIOUS_POSITION: + buffer_cursor_move_to_prev_pos(buffer); + break; case CMD_INSERT_TEXT: { const char *str = arg_get_string(ted, argument); @@ -47,6 +47,7 @@ typedef enum { CMD_START_OF_FILE, /// move cursor to end of buffer CMD_END_OF_FILE, + CMD_PREVIOUS_POSITION, CMD_SELECT_START_OF_FILE, CMD_SELECT_END_OF_FILE, /// select entire buffer @@ -6,7 +6,6 @@ FUTURE FEATURES: - styles ([color] sections) - for this, it would be nice to have #include in ted.cfg - make go-to-definition/hover/highlight modifier key configurable -- return to previous location in buffer - font setting & support for multiple fonts to cover more characters - support for variable-width fonts - robust find (results shouldn't move around when you type things) @@ -211,6 +211,8 @@ Shift+End = :select-end-of-line Ctrl+End = :end-of-file Ctrl+Shift+End = :select-end-of-file Ctrl+a = :select-all +# go to previous cursor position +Ctrl+p = :previous-position # insertion Tab = :tab @@ -342,6 +342,8 @@ typedef struct { BufferPos cursor_pos; /// if `selection` is true, the text between `selection_pos` and `cursor_pos` is selected. BufferPos selection_pos; + /// "previous" position of cursor, for CMD_PREVIOUS_POSITION + BufferPos prev_cursor_pos; /// "line buffers" are buffers which can only have one line of text (used for inputs) bool is_line_buffer; /// is anything selected? @@ -975,6 +977,8 @@ i64 buffer_pos_move_right_words(TextBuffer *buffer, BufferPos *pos, i64 nwords); i64 buffer_cursor_move_left_words(TextBuffer *buffer, i64 nwords); /// returns the number of words successfully moved by. i64 buffer_cursor_move_right_words(TextBuffer *buffer, i64 nwords); +/// move cursor to "previous" position (i.e. \ref CMD_PREVIOUS_POSITION) +void buffer_cursor_move_to_prev_pos(TextBuffer *buffer); /// Returns a string of word characters (see is32_word) around the position, /// or an empty string if neither of the characters to the left and right of the cursor are word characters. /// NOTE: The string is invalidated when the buffer is changed!!! |