tFind occurences correctly on first and later lines - ve - a minimal text editor (work in progress)
(HTM) git clone git://src.adamsgaard.dk/ve
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 893395f4cbc488e2fa942f80589d563c7648fb6e
(DIR) parent dce7e854fa36dd6392e73c208140c570644ad7dc
(HTM) Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Wed, 7 Aug 2019 10:35:49 +0200
Find occurences correctly on first and later lines
Diffstat:
M find.c | 38 +++++++++++++++++++------------
M main.c | 2 +-
2 files changed, 25 insertions(+), 15 deletions(-)
---
(DIR) diff --git a/find.c b/find.c
t@@ -16,33 +16,43 @@
void
editor_find_next_occurence(int opposite_direction)
{
- int i;
+ int x_start;
+ int y_start, y, y_end, y_inc;
eRow *row;
char *match;
-
+
if (!E.find_query)
return;
+ y_start = E.cursor_y;
+ x_start = editor_row_cursor_x_to_rx(&E.row[E.cursor_y], E.cursor_x);
+
if ((E.find_direction && !opposite_direction) ||
(!E.find_direction && opposite_direction)) {
- for (i=0; i<E.num_rows; ++i) {
- row = &E.row[i];
- match = strstr(row->rchars, E.find_query);
- if (match)
- break;
- }
+ y_end = E.num_rows;
+ y_inc = +1;
} else {
- for (i=E.num_rows-1; i>=0; --i) {
- row = &E.row[i];
+ y_end = -1;
+ y_inc = -1;
+ }
+
+ /* from cursor until end of document */
+ for (y = y_start; y != y_end; y += y_inc) {
+ row = &E.row[y];
+
+ if (y == y_start)
+ match = strstr(row->rchars + x_start, E.find_query);
+ else
match = strstr(row->rchars, E.find_query);
- if (match)
- break;
- }
+ if (match)
+ break;
}
if (match) {
- E.cursor_y = i;
+ E.cursor_y = y;
E.cursor_x = editor_row_cursor_rx_to_x(row, match - row->rchars);
/* E.row_offset = E.num_rows; */ /* put line to top of screen */
+ } else {
+ /* from other end of document until cursor */
}
}
(DIR) diff --git a/main.c b/main.c
t@@ -17,7 +17,7 @@ main(int argc, char* argv[])
file_open(argv[1]);
}
- editor_set_status_message("-- %s v%s --", PROGNAME, VERSION);
+ editor_set_status_message("%s v%s", PROGNAME, VERSION);
while (1) {
editor_refresh_screen();