чување 2000ba30c03555225190c6e3ab0bc9c49182c050
родитељ b0258974f7c90d22256741300a1161a5de9ba244
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Sat, 1 Apr 2023 00:45:10 +0200
Add replacement in selection; clear search text after replace; do not find next match on search step in search & replace
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
измењених датотека: 2, додавања: 53(+), брисања: 5(-)
diff --git a/search_and_replace b/search_and_replace
@@ -0,0 +1,32 @@
+ BCD -> KLMNO
+ search_len = 3
+
+ state->buffer[row].length = 9
+
+
+ ,- state->buffer[row].text
+ |
+ | ,- state->buffer[row].text
+ | | + state->buffer[row].length = 9
+ 0 1 2 3 4 5 6 7 8 9
+ A B C D E F G H I \0
+ | |
+ | |
+ | `- found + search_len = after
+ `- found
+
+
+
+ ,- state->buffer[row].text
+ |
+ | ,- state->buffer[row].text
+ | | + state->buffer[row].length = 9
+ 0 1 2 3 4 5 6 7 8 9
+ A G H I E F B C D \0 (but *after == 0, so...)
+ | |
+ | |
+ | `- found + search_len = after
+ `- found
+
+
+
diff --git a/sled.c b/sled.c
@@ -130,9 +130,24 @@ do_search_replace(struct DrawState* state)
{
uint32_t buf[MAXBUFLINE];
size_t search_len = u32_strlen(state->search);
+ int start_row = 0;
+ int end_row = state->rows_count;
- // TODO: Replace in selection?
- for (int row = 0; row < state->rows_count; row++)
+ if (SEL_NOT_EMPTY(state))
+ {
+ if (state->sel_start.row <= state->sel_end.row)
+ {
+ start_row = state->sel_start.row;
+ end_row = state->sel_end.row;
+ }
+ else /* Swap */
+ {
+ start_row = state->sel_end.row;
+ end_row = state->sel_start.row;
+ }
+ }
+
+ for (int row = start_row; row < end_row; row++)
{
const uint32_t* before = state->buffer[row].text;
uint32_t* found = (uint32_t*)u32_strstr(before, state->search);
@@ -917,7 +932,7 @@ search_dialog_callback(struct DrawState* state)
void
search_replace_search_dialog_callback(struct DrawState* state)
{
- next_match(state);
+ /*next_match(state);*/
if (!*state->error)
state->input_callback = NULL;
*state->input = 0;
@@ -928,8 +943,9 @@ void
search_replace_replace_dialog_callback(struct DrawState* state)
{
do_search_replace(state);
- u32_strcpy(state->search, state->input);
- next_match(state);
+ *state->search = 0;
+ /*u32_strcpy(state->search, state->input);
+ next_match(state);*/
if (!*state->error)
state->input_callback = NULL;
state->chain_dialog = 0;