summaryrefslogtreecommitdiff
path: root/find.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2021-02-11 15:13:11 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2021-02-11 15:13:11 -0500
commit9396a9f602727bc78d7c9dcc95142038edfad51a (patch)
treeb6afc92e959590ebde903969f914459e9d25c760 /find.c
parent143ed955b939b3292801fb9503ad8759467defcd (diff)
fixed some problems with find+replace
Diffstat (limited to 'find.c')
-rw-r--r--find.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/find.c b/find.c
index 805210a..6b8da61 100644
--- a/find.c
+++ b/find.c
@@ -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);
}