tConsolidate search logic, reverse search still with issues - 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 07818975aa5dc5dc2c512488a9cea75711e44b56
 (DIR) parent 745e1e2448e41ce7fe8917b5202ff8dfb24117ef
 (HTM) Author: Anders Damsgaard <anders@adamsgaard.dk>
       Date:   Wed,  7 Aug 2019 11:58:04 +0200
       
       Consolidate search logic, reverse search still with issues
       
       Diffstat:
         M find.c                              |      27 +++++++++++++++++++--------
       
       1 file changed, 19 insertions(+), 8 deletions(-)
       ---
 (DIR) diff --git a/find.c b/find.c
       t@@ -16,7 +16,7 @@
        void
        editor_find_next_occurence(int opposite_direction)
        {
       -        int y, y_end, y_inc, x_offset;
       +        int y, y_inc, x_offset;
                eRow *row;
                char *match;
        
       t@@ -24,17 +24,16 @@ editor_find_next_occurence(int opposite_direction)
                        return;
        
                if ((E.find_direction && !opposite_direction) ||
       -                (!E.find_direction && opposite_direction)) {
       -                y_end = E.num_rows;
       +                (!E.find_direction && opposite_direction))
                        y_inc = +1;
       -        } else {
       -                y_end = -1;
       +        else
                        y_inc = -1;
       -        }
        
                x_offset = 0;
                /* from cursor until end of document */
       -        for (y = E.cursor_y; y != y_end; y += y_inc) {
       +        for (y = E.cursor_y;
       +             y != ((y_inc == +1) ? E.num_rows : -1);
       +             y += y_inc) {
                        row = &E.row[y];
        
                        if (y == E.cursor_y)
       t@@ -53,7 +52,19 @@ editor_find_next_occurence(int opposite_direction)
                        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 */
       +                /* from other end of file until cursor */
       +                editor_set_status_message("wrapping search");
       +                for (y = (y_inc == +1) ? 0 : E.num_rows - 1;
       +                     y != E.cursor_y + y_inc;
       +                     y += y_inc) {
       +                        match = strstr(row->rchars, E.find_query);
       +                        if (match)
       +                                break;
       +                }
       +                if (match) {
       +                        E.cursor_y = y;
       +                        E.cursor_x = editor_row_cursor_rx_to_x(row, match - row->rchars);
       +                }
                }
        }