diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2021-02-11 15:13:11 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2021-02-11 15:13:11 -0500 |
commit | 9396a9f602727bc78d7c9dcc95142038edfad51a (patch) | |
tree | b6afc92e959590ebde903969f914459e9d25c760 | |
parent | 143ed955b939b3292801fb9503ad8759467defcd (diff) |
fixed some problems with find+replace
-rw-r--r-- | buffer.c | 1 | ||||
-rw-r--r-- | command.c | 8 | ||||
-rw-r--r-- | find.c | 21 |
3 files changed, 20 insertions, 10 deletions
@@ -518,6 +518,7 @@ static bool buffer_edit_does_anything(TextBuffer *buffer, BufferEdit *edit) { static bool buffer_edit_split(TextBuffer *buffer) { BufferEdit *last_edit = arr_lastp(buffer->undo_history); if (!last_edit) return true; + if (buffer->will_chain_edits) return true; if (buffer->chaining_edits) return false; double curr_time = time_get_seconds(); double undo_time_cutoff = buffer_settings(buffer)->undo_save_time; // only keep around edits for this long (in seconds). @@ -99,7 +99,7 @@ void command_execute(Ted *ted, Command c, i64 argument) { case CMD_TAB: if (ted->replace && buffer == &ted->find_buffer) { - ted->active_buffer = &ted->replace_buffer; + buffer = ted->active_buffer = &ted->replace_buffer; buffer_select_all(buffer); } else if (buffer) { if (buffer->selection) @@ -109,9 +109,9 @@ void command_execute(Ted *ted, Command c, i64 argument) { } break; case CMD_BACKTAB: - if (ted->replace && ted->active_buffer == &ted->replace_buffer) { - ted->active_buffer = &ted->find_buffer; - buffer_select_all(ted->active_buffer); + if (ted->replace && buffer == &ted->replace_buffer) { + buffer = ted->active_buffer = &ted->find_buffer; + buffer_select_all(buffer); } else if (buffer) { if (buffer->selection) buffer_dedent_selection(buffer); @@ -150,6 +150,7 @@ static void find_update(Ted *ted, bool force) { // returns the index of the match we are "on", or U32_MAX for none. static u32 find_match_idx(Ted *ted) { + find_update(ted, false); TextBuffer *buffer = ted->prev_active_buffer; if (!buffer->selection) return U32_MAX; u32 match_idx = U32_MAX; @@ -173,11 +174,16 @@ static void find_next_in_direction(Ted *ted, int direction) { for (size_t nsearches = 0; nsearches < nlines + 1; ++nsearches) { u32 match_start, match_end; if (find_match(ted, &pos, &match_start, &match_end, direction)) { - BufferPos pos_start = {.line = pos.line, .index = match_start}; - BufferPos pos_end = {.line = pos.line, .index = match_end}; - buffer_cursor_move_to_pos(buffer, pos_start); - buffer_select_to_pos(buffer, pos_end); - break; + if (nsearches == 0 && match_start == buffer->cursor_pos.index) { + // if you click "next" and your cursor is on a match, it should go to the next + // one, not the one you're on + } else { + BufferPos pos_start = {.line = pos.line, .index = match_start}; + BufferPos pos_end = {.line = pos.line, .index = match_end}; + buffer_cursor_move_to_pos(buffer, pos_start); + buffer_select_to_pos(buffer, pos_end); + break; + } } } } @@ -248,13 +254,16 @@ static void find_replace(Ted *ted) { if (match_idx != U32_MAX) { buffer_cursor_move_to_pos(buffer, ted->find_results[match_idx].start); // move to start of match find_replace_match(ted, match_idx); + find_update(ted, true); } } // go to next find result static void find_next(Ted *ted) { - if (ted->replace) + if (ted->replace) { find_replace(ted); + find_update(ted, true); + } find_next_in_direction(ted, +1); } |