summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--buffer.c1
-rw-r--r--command.c8
-rw-r--r--find.c21
3 files changed, 20 insertions, 10 deletions
diff --git a/buffer.c b/buffer.c
index dfca9f8..9ac5fd5 100644
--- a/buffer.c
+++ b/buffer.c
@@ -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).
diff --git a/command.c b/command.c
index 9cc7ad7..8db46f9 100644
--- a/command.c
+++ b/command.c
@@ -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);
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);
}