чување 30a2eb1dc3737377ec9a24eecafa631bca19798a
родитељ 2000ba30c03555225190c6e3ab0bc9c49182c050
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Mon, 3 Apr 2023 08:54:59 +0200
Fix: prev_match was skipping some matches due to redundant code; Move all ASCII drawings into the notes subdir
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
измењених датотека: 5, додавања: 55(+), брисања: 12(-)
diff --git a/delete.selection b/notes/delete_selection
diff --git a/paste_selection b/notes/paste_selection
diff --git a/notes/prev_match b/notes/prev_match
@@ -0,0 +1,48 @@
+
+
+
+
+
+
+
+
+ 0 1 2 3 4 5 6 7 8 9 A
+ H E L L O W O R L D
+ H E L L O
+ | _
+ |
+ | \
+ | state->coord.col == 7
+ |
+ | search == HELLO
+ | search_len == 5
+ |
+ `--------- found += 7 - 5 + 1 == 3
+
+
+
+ 0 1 2 3 4 5 6 7 8 9 A B C D E F
+ H E S A I D " H E L L O " ,
+ H E L L O
+ |
+ | current->length == 16
+ |
+ | search_len == 5
+ |
+ `- found += 16 - 5 + 1 == 12
+ idelta == 12
+
+
+ 0 1 2 3 4 5 6 7 8 9 A B C D E F
+
+ N O T K N O W I N G T H A T
+ _
+
+
+
+
+
+
+
+
+
diff --git a/search_and_replace b/notes/search_and_replace
diff --git a/sled.c b/sled.c
@@ -1728,27 +1728,22 @@ prev_match(struct DrawState* state)
struct BufferLine* current = NULL;
const uint32_t* found = NULL;
size_t idelta;
- size_t search_len;
if (!state->search || !*state->search)
return 0;
*state->error = 0;
- search_len = u32_strlen(state->search);
- for (size_t row = state->coord.row + 1; row > 0; row--)
+ for (size_t row = state->coord.row; row >= 0; row--)
{
const uint32_t* save_found;
- current = state->buffer + row - 1;
+ current = state->buffer + row;
found = current->text;
if (!found)
return 0;
- if (row == state->coord.row + 1)
- {
- if (state->coord.col > search_len)
- found += state->coord.col - search_len + 1;
- }
- else if (current->length > search_len)
- found += current->length - search_len + 1;
+ if (row == state->coord.row)
+ found += state->coord.col;
+ else
+ found += current->length;
prev_match_loop:
save_found = found;
@@ -1760,7 +1755,7 @@ prev_match(struct DrawState* state)
= display_length(state, current->text, idelta);
if (*current->text)
{
- position_to(state, row - 1, idelta);
+ position_to(state, row, idelta);
return 0;
}
}