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 /buffer.c | |
parent | 189bbdf3e1d5285fc0508d1a190036d6f4295558 (diff) |
select all
Diffstat (limited to 'buffer.c')
-rw-r--r-- | buffer.c | 20 |
1 files changed, 12 insertions, 8 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); |