Only search the visible part of the history when marking (highlighting)

search terms, much faster than searching the whole history.
This commit is contained in:
nicm 2020-04-02 17:03:10 +00:00
parent 90f4e149c1
commit a20d96000e

View File

@ -509,6 +509,8 @@ window_copy_pageup1(struct window_mode_entry *wme, int half_page)
window_copy_cursor_end_of_line(wme); window_copy_cursor_end_of_line(wme);
} }
if (data->searchmark != NULL && !data->timeout)
window_copy_search_marks(wme, NULL, data->searchregex);
window_copy_update_selection(wme, 1, 0); window_copy_update_selection(wme, 1, 0);
window_copy_redraw_screen(wme); window_copy_redraw_screen(wme);
} }
@ -557,6 +559,8 @@ window_copy_pagedown(struct window_mode_entry *wme, int half_page,
if (scroll_exit && data->oy == 0) if (scroll_exit && data->oy == 0)
return (1); return (1);
if (data->searchmark != NULL && !data->timeout)
window_copy_search_marks(wme, NULL, data->searchregex);
window_copy_update_selection(wme, 1, 0); window_copy_update_selection(wme, 1, 0);
window_copy_redraw_screen(wme); window_copy_redraw_screen(wme);
return (0); return (0);
@ -1049,6 +1053,8 @@ window_copy_cmd_history_bottom(struct window_copy_cmd_state *cs)
data->cx = window_copy_find_length(wme, data->cy); data->cx = window_copy_find_length(wme, data->cy);
data->oy = 0; data->oy = 0;
if (data->searchmark != NULL && !data->timeout)
window_copy_search_marks(wme, NULL, data->searchregex);
window_copy_update_selection(wme, 1, 0); window_copy_update_selection(wme, 1, 0);
return (WINDOW_COPY_CMD_REDRAW); return (WINDOW_COPY_CMD_REDRAW);
} }
@ -1068,6 +1074,8 @@ window_copy_cmd_history_top(struct window_copy_cmd_state *cs)
data->cx = 0; data->cx = 0;
data->oy = screen_hsize(data->backing); data->oy = screen_hsize(data->backing);
if (data->searchmark != NULL && !data->timeout)
window_copy_search_marks(wme, NULL, data->searchregex);
window_copy_update_selection(wme, 1, 0); window_copy_update_selection(wme, 1, 0);
return (WINDOW_COPY_CMD_REDRAW); return (WINDOW_COPY_CMD_REDRAW);
} }
@ -2200,6 +2208,8 @@ window_copy_scroll_to(struct window_mode_entry *wme, u_int px, u_int py)
data->oy = gd->hsize - offset; data->oy = gd->hsize - offset;
} }
if (data->searchmark != NULL && !data->timeout)
window_copy_search_marks(wme, NULL, data->searchregex);
window_copy_update_selection(wme, 1, 0); window_copy_update_selection(wme, 1, 0);
window_copy_redraw_screen(wme); window_copy_redraw_screen(wme);
} }
@ -2777,6 +2787,7 @@ window_copy_search_marks(struct window_mode_entry *wme, struct screen *ssp,
struct screen *s = data->backing, ss; struct screen *s = data->backing, ss;
struct screen_write_ctx ctx; struct screen_write_ctx ctx;
struct grid *gd = s->grid; struct grid *gd = s->grid;
const struct grid_line *gl;
int found, cis, which = -1; int found, cis, which = -1;
int cflags = REG_EXTENDED; int cflags = REG_EXTENDED;
u_int px, py, b, nfound = 0, width; u_int px, py, b, nfound = 0, width;
@ -2814,7 +2825,15 @@ window_copy_search_marks(struct window_mode_entry *wme, struct screen *ssp,
} }
} }
time(&tstart); time(&tstart);
for (py = 0; py < gd->hsize + gd->sy; py++) { py = gd->hsize - data->oy;
if (py > 0)
py--;
for (; py > 0; py--) {
gl = grid_peek_line(gd, py);
if (~gl->flags & GRID_LINE_WRAPPED)
break;
}
for (; py < gd->hsize - data->oy + gd->sy; py++) {
px = 0; px = 0;
for (;;) { for (;;) {
if (regex) { if (regex) {
@ -4190,6 +4209,8 @@ window_copy_scroll_up(struct window_mode_entry *wme, u_int ny)
return; return;
data->oy -= ny; data->oy -= ny;
if (data->searchmark != NULL && !data->timeout)
window_copy_search_marks(wme, NULL, data->searchregex);
window_copy_update_selection(wme, 0, 0); window_copy_update_selection(wme, 0, 0);
screen_write_start(&ctx, wp, NULL); screen_write_start(&ctx, wp, NULL);
@ -4224,6 +4245,8 @@ window_copy_scroll_down(struct window_mode_entry *wme, u_int ny)
return; return;
data->oy += ny; data->oy += ny;
if (data->searchmark != NULL && !data->timeout)
window_copy_search_marks(wme, NULL, data->searchregex);
window_copy_update_selection(wme, 0, 0); window_copy_update_selection(wme, 0, 0);
screen_write_start(&ctx, wp, NULL); screen_write_start(&ctx, wp, NULL);