diff options
author | pommicket <pommicket@gmail.com> | 2023-01-02 19:26:15 -0500 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2023-01-02 19:26:15 -0500 |
commit | 2e4853a94693d9bb22539bffb8114e3845f22128 (patch) | |
tree | 1397271d497235de97cf4fa3b0fd2faeeb37fcc7 | |
parent | 29824f8bef3dde9b091185be295de3ae07ee17fd (diff) |
fix problem where backspacing selection puts cursor in weird place
-rw-r--r-- | buffer.c | 22 |
1 files changed, 13 insertions, 9 deletions
@@ -2099,13 +2099,15 @@ i64 buffer_backspace_at_pos(TextBuffer *buffer, BufferPos *pos, i64 ntimes) { // returns number of characters backspaced i64 buffer_backspace_at_cursor(TextBuffer *buffer, i64 ntimes) { - i64 ret = 0; - BufferPos cursor_pos = buffer->cursor_pos; - if (buffer->selection) + i64 ret=0; + if (buffer->selection) { ret = buffer_delete_selection(buffer); - else + } else { + BufferPos cursor_pos = buffer->cursor_pos; ret = buffer_backspace_at_pos(buffer, &cursor_pos, ntimes); - buffer_cursor_move_to_pos(buffer, cursor_pos); + buffer_cursor_move_to_pos(buffer, cursor_pos); + } + buffer_scroll_to_cursor(buffer); return ret; } @@ -2130,12 +2132,14 @@ void buffer_backspace_words_at_pos(TextBuffer *buffer, BufferPos *pos, i64 nword } void buffer_backspace_words_at_cursor(TextBuffer *buffer, i64 nwords) { - BufferPos cursor_pos = buffer->cursor_pos; - if (buffer->selection) + if (buffer->selection) { buffer_delete_selection(buffer); - else + } else { + BufferPos cursor_pos = buffer->cursor_pos; buffer_backspace_words_at_pos(buffer, &cursor_pos, nwords); - buffer_cursor_move_to_pos(buffer, cursor_pos); + buffer_cursor_move_to_pos(buffer, cursor_pos); + } + buffer_scroll_to_cursor(buffer); } // puts the inverse edit into `inverse` |