summaryrefslogtreecommitdiff
path: root/find.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2021-02-10 10:17:06 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2021-02-11 14:50:02 -0500
commit4f2a012a5dbad755bd621a3308a306afd4589fd5 (patch)
tree84cce3eb1da5f4140e8b83ed307aa361a9cacf1b /find.c
parentc67be90a777430e73c4817d1612cf9eb41b2ad87 (diff)
make find+replace more convenient
Diffstat (limited to 'find.c')
-rw-r--r--find.c54
1 files changed, 27 insertions, 27 deletions
diff --git a/find.c b/find.c
index 6b237f2..48a9299 100644
--- a/find.c
+++ b/find.c
@@ -58,25 +58,6 @@ static void find_free_pattern(Ted *ted) {
arr_clear(ted->find_results);
}
-static void find_open(Ted *ted, bool replace) {
- if (!ted->find && ted->active_buffer) {
- ted->prev_active_buffer = ted->active_buffer;
- ted->active_buffer = &ted->find_buffer;
- ted->find = true;
- buffer_clear(&ted->find_buffer);
- }
- if (!ted->replace && replace) {
- ted->replace = true;
- buffer_clear(&ted->replace_buffer);
- }
-}
-
-static void find_close(Ted *ted) {
- ted->find = false;
- ted->active_buffer = ted->prev_active_buffer;
- find_free_pattern(ted);
-}
-
static float find_menu_height(Ted *ted) {
Font *font = ted->font;
float char_height = text_font_char_height(font);
@@ -130,10 +111,11 @@ static WarnUnusedResult bool find_match(Ted *ted, BufferPos *pos, u32 *match_sta
}
// check if the search term needs to be recompiled
-static void find_update(Ted *ted) {
+static void find_update(Ted *ted, bool force) {
TextBuffer *find_buffer = &ted->find_buffer;
u32 flags = find_compilation_flags(ted);
- if (!find_buffer->modified // check if buffer has been modified,
+ if (!force
+ && !find_buffer->modified // check if buffer has been modified,
&& ted->find_flags == flags) // or checkboxes have been (un)checked
return;
ted->find_flags = flags;
@@ -202,6 +184,9 @@ static void find_next_in_direction(Ted *ted, int direction) {
// returns true if successful
static bool find_replace_match(Ted *ted, u32 match_idx) {
+ find_update(ted, false);
+ if (!ted->find_code) return false;
+
bool success = false;
FindResult match = ted->find_results[match_idx];
TextBuffer *buffer = ted->prev_active_buffer;
@@ -268,16 +253,12 @@ static void find_replace(Ted *ted) {
// go to next find result
static void find_next(Ted *ted) {
- find_update(ted);
- if (!ted->find_code) return;
-
if (ted->replace)
find_replace(ted);
find_next_in_direction(ted, +1);
}
static void find_prev(Ted *ted) {
- find_update(ted);
find_next_in_direction(ted, -1);
}
@@ -296,7 +277,7 @@ static void find_replace_all(Ted *ted) {
if (!find_replace_match(ted, i))
break;
}
- find_update(ted);
+ find_update(ted, true);
}
}
}
@@ -363,7 +344,7 @@ static void find_menu_frame(Ted *ted) {
find_replace_all(ted);
}
- find_update(ted);
+ find_update(ted, false);
arr_foreach_ptr(ted->find_results, FindResult, result) {
// highlight matches
BufferPos p1 = result->start, p2 = result->end;
@@ -450,3 +431,22 @@ static void find_menu_frame(Ted *ted) {
gl_geometry_draw();
}
+
+static void find_open(Ted *ted, bool replace) {
+ if (!ted->find && ted->active_buffer) {
+ ted->prev_active_buffer = ted->active_buffer;
+ ted->active_buffer = &ted->find_buffer;
+ ted->find = true;
+ buffer_select_all(ted->active_buffer);
+ }
+ if (!ted->replace && replace) {
+ ted->replace = true;
+ }
+ find_update(ted, true);
+}
+
+static void find_close(Ted *ted) {
+ ted->find = false;
+ ted->active_buffer = ted->prev_active_buffer;
+ find_free_pattern(ted);
+}