diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2021-01-02 18:10:09 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2021-01-02 18:10:09 -0500 |
commit | 6bafd0d45f63a7618d7822f31b01da7443d9c5e8 (patch) | |
tree | 35ad964886abc69ee55af39ba1130342cd1155b0 | |
parent | 189bbdf3e1d5285fc0508d1a190036d6f4295558 (diff) |
select all
-rw-r--r-- | buffer.c | 20 | ||||
-rw-r--r-- | command.c | 3 | ||||
-rw-r--r-- | command.h | 4 | ||||
-rw-r--r-- | ted.cfg | 3 |
4 files changed, 20 insertions, 10 deletions
@@ -144,12 +144,12 @@ char32_t buffer_char_at_pos(TextBuffer *buffer, BufferPos p) { } } -BufferPos buffer_pos_start_of_file(TextBuffer *buffer) { +BufferPos buffer_start_of_file(TextBuffer *buffer) { (void)buffer; return (BufferPos){.line = 0, .index = 0}; } -BufferPos buffer_pos_end_of_file(TextBuffer *buffer) { +BufferPos buffer_end_of_file(TextBuffer *buffer) { return (BufferPos){.line = buffer->nlines - 1, .index = buffer->lines[buffer->nlines-1].len}; } @@ -220,7 +220,7 @@ static BufferPos buffer_pos_advance(TextBuffer *buffer, BufferPos pos, size_t nc index = 0; ++line; } - return buffer_pos_end_of_file(buffer); + return buffer_end_of_file(buffer); } @@ -834,7 +834,7 @@ i64 buffer_pos_move_horizontally(TextBuffer *buffer, BufferPos *p, i64 by) { } else if (by > 0) { i64 by_start = by; if (p->line >= buffer->nlines) - *p = buffer_pos_end_of_file(buffer); // invalid position; move to end of buffer + *p = buffer_end_of_file(buffer); // invalid position; move to end of buffer Line *line = &buffer->lines[p->line]; while (by > 0) { if (by <= line->len - p->index) { @@ -1081,11 +1081,11 @@ void buffer_cursor_move_to_end_of_line(TextBuffer *buffer) { } void buffer_cursor_move_to_start_of_file(TextBuffer *buffer) { - buffer_cursor_move_to_pos(buffer, buffer_pos_start_of_file(buffer)); + buffer_cursor_move_to_pos(buffer, buffer_start_of_file(buffer)); } void buffer_cursor_move_to_end_of_file(TextBuffer *buffer) { - buffer_cursor_move_to_pos(buffer, buffer_pos_end_of_file(buffer)); + buffer_cursor_move_to_pos(buffer, buffer_end_of_file(buffer)); } // insert `number` empty lines starting at index `where`. @@ -1243,11 +1243,11 @@ void buffer_select_to_end_of_line(TextBuffer *buffer) { } void buffer_select_to_start_of_file(TextBuffer *buffer) { - buffer_select_to_pos(buffer, buffer_pos_start_of_file(buffer)); + buffer_select_to_pos(buffer, buffer_start_of_file(buffer)); } void buffer_select_to_end_of_file(TextBuffer *buffer) { - buffer_select_to_pos(buffer, buffer_pos_end_of_file(buffer)); + buffer_select_to_pos(buffer, buffer_end_of_file(buffer)); } // select the word the cursor is inside of @@ -1269,6 +1269,10 @@ void buffer_select_line(TextBuffer *buffer) { buffer_select_to_pos(buffer, buffer_pos_start_of_line(buffer, line)); } +void buffer_select_all(TextBuffer *buffer) { + buffer_cursor_move_to_pos(buffer, buffer_start_of_file(buffer)); + buffer_select_to_pos(buffer, buffer_end_of_file(buffer)); +} static void buffer_shorten_line(Line *line, u32 new_len) { assert(line->len >= new_len); @@ -87,6 +87,9 @@ void command_execute(Ted *ted, Command c, i64 argument) { case CMD_SELECT_END_OF_FILE: buffer_select_to_end_of_file(buffer); break; + case CMD_SELECT_ALL: + buffer_select_all(buffer); + break; case CMD_BACKSPACE: buffer_backspace_at_cursor(buffer, argument); @@ -1,7 +1,7 @@ ENUM_U16 { CMD_UNKNOWN, CMD_NOOP, - // movement commands + // movement and selection commands CMD_LEFT, CMD_RIGHT, CMD_UP, @@ -22,6 +22,7 @@ ENUM_U16 { CMD_END_OF_FILE, CMD_SELECT_START_OF_FILE, CMD_SELECT_END_OF_FILE, + CMD_SELECT_ALL, // scrolling CMD_PAGE_UP, @@ -67,6 +68,7 @@ static CommandName const command_names[CMD_COUNT] = { {"end-of-file", CMD_END_OF_FILE}, {"select-start-of-file", CMD_SELECT_START_OF_FILE}, {"select-end-of-file", CMD_SELECT_END_OF_FILE}, + {"select-all", CMD_SELECT_ALL}, {"page-up", CMD_PAGE_UP}, {"page-down", CMD_PAGE_DOWN}, {"backspace", CMD_BACKSPACE}, @@ -6,7 +6,7 @@ cursor-width = 1 undo-save-time = 6 [keyboard] -# motion keys +# motion and selection Left = :left Shift+Left = :select-left Ctrl+Left = :left-word @@ -31,6 +31,7 @@ End = :end-of-line Shift+End = :select-end-of-line Ctrl+End = :end-of-file Ctrl+Shift+End = :select-end-of-file +Ctrl+a = :select-all # deletion Delete = :delete |