=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/window-copy.c,v retrieving revision 1.295 retrieving revision 1.296 diff -c -r1.295 -r1.296 *** src/usr.bin/tmux/window-copy.c 2020/06/04 10:24:14 1.295 --- src/usr.bin/tmux/window-copy.c 2020/06/04 20:41:57 1.296 *************** *** 1,4 **** ! /* $OpenBSD: window-copy.c,v 1.295 2020/06/04 10:24:14 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: window-copy.c,v 1.296 2020/06/04 20:41:57 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott *************** *** 52,58 **** static void window_copy_write_lines(struct window_mode_entry *, struct screen_write_ctx *, u_int, u_int); ! static void window_copy_scroll_to(struct window_mode_entry *, u_int, u_int); static int window_copy_search_compare(struct grid *, u_int, u_int, struct grid *, u_int, int); static int window_copy_search_lr(struct grid *, struct grid *, u_int *, --- 52,59 ---- static void window_copy_write_lines(struct window_mode_entry *, struct screen_write_ctx *, u_int, u_int); ! static void window_copy_scroll_to(struct window_mode_entry *, u_int, u_int, ! int); static int window_copy_search_compare(struct grid *, u_int, u_int, struct grid *, u_int, int); static int window_copy_search_lr(struct grid *, struct grid *, u_int *, *************** *** 67,73 **** static void window_copy_cstrtocellpos(struct grid *, u_int, u_int *, u_int *, const char *str); static int window_copy_search_marks(struct window_mode_entry *, ! struct screen *, int); static void window_copy_clear_marks(struct window_mode_entry *); static void window_copy_move_left(struct screen *, u_int *, u_int *, int); static void window_copy_move_right(struct screen *, u_int *, u_int *, int); --- 68,74 ---- static void window_copy_cstrtocellpos(struct grid *, u_int, u_int *, u_int *, const char *str); static int window_copy_search_marks(struct window_mode_entry *, ! struct screen *, int, int); static void window_copy_clear_marks(struct window_mode_entry *); static void window_copy_move_left(struct screen *, u_int *, u_int *, int); static void window_copy_move_right(struct screen *, u_int *, u_int *, int); *************** *** 265,270 **** --- 266,272 ---- u_int my; int showmark; + uint64_t searchtime; int searchtype; int searchregex; char *searchstr; *************** *** 280,285 **** --- 282,288 ---- int timeout; /* search has timed out */ #define WINDOW_COPY_SEARCH_TIMEOUT 10000 #define WINDOW_COPY_SEARCH_ALL_TIMEOUT 200 + #define WINDOW_COPY_SEARCH_REPEAT 50 int jumptype; char jumpchar; *************** *** 588,594 **** } if (data->searchmark != NULL && !data->timeout) ! window_copy_search_marks(wme, NULL, data->searchregex); window_copy_update_selection(wme, 1, 0); window_copy_redraw_screen(wme); } --- 591,597 ---- } if (data->searchmark != NULL && !data->timeout) ! window_copy_search_marks(wme, NULL, data->searchregex, 1); window_copy_update_selection(wme, 1, 0); window_copy_redraw_screen(wme); } *************** *** 638,644 **** if (scroll_exit && data->oy == 0) 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_redraw_screen(wme); return (0); --- 641,647 ---- if (scroll_exit && data->oy == 0) return (1); if (data->searchmark != NULL && !data->timeout) ! window_copy_search_marks(wme, NULL, data->searchregex, 1); window_copy_update_selection(wme, 1, 0); window_copy_redraw_screen(wme); return (0); *************** *** 658,664 **** while (oy > 0 && window_copy_find_length(wme, oy) > 0) oy--; ! window_copy_scroll_to(wme, 0, oy); } static void --- 661,667 ---- while (oy > 0 && window_copy_find_length(wme, oy) > 0) oy--; ! window_copy_scroll_to(wme, 0, oy, 0); } static void *************** *** 678,684 **** oy++; ox = window_copy_find_length(wme, oy); ! window_copy_scroll_to(wme, ox, oy); } char * --- 681,687 ---- oy++; ox = window_copy_find_length(wme, oy); ! window_copy_scroll_to(wme, ox, oy, 0); } char * *************** *** 754,760 **** screen_write_stop(&ctx); if (search && !data->timeout) ! window_copy_search_marks(wme, NULL, data->searchregex); data->searchx = data->cx; data->searchy = data->cy; data->searcho = data->oy; --- 757,763 ---- screen_write_stop(&ctx); if (search && !data->timeout) ! window_copy_search_marks(wme, NULL, data->searchregex, 0); data->searchx = data->cx; data->searchy = data->cy; data->searcho = data->oy; *************** *** 1150,1156 **** data->oy = 0; if (data->searchmark != NULL && !data->timeout) ! window_copy_search_marks(wme, NULL, data->searchregex); window_copy_update_selection(wme, 1, 0); return (WINDOW_COPY_CMD_REDRAW); } --- 1153,1159 ---- data->oy = 0; if (data->searchmark != NULL && !data->timeout) ! window_copy_search_marks(wme, NULL, data->searchregex, 1); window_copy_update_selection(wme, 1, 0); return (WINDOW_COPY_CMD_REDRAW); } *************** *** 1171,1177 **** 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); return (WINDOW_COPY_CMD_REDRAW); } --- 1174,1180 ---- data->oy = screen_hsize(data->backing); if (data->searchmark != NULL && !data->timeout) ! window_copy_search_marks(wme, NULL, data->searchregex, 1); window_copy_update_selection(wme, 1, 0); return (WINDOW_COPY_CMD_REDRAW); } *************** *** 1325,1331 **** /* Move the cursor to the found location if any. */ if (!failed) ! window_copy_scroll_to(wme, px, py); } return (WINDOW_COPY_CMD_NOTHING); --- 1328,1334 ---- /* Move the cursor to the found location if any. */ if (!failed) ! window_copy_scroll_to(wme, px, py, 0); } return (WINDOW_COPY_CMD_NOTHING); *************** *** 1376,1382 **** sx = data->cx; sy = screen_hsize(s) + data->cy - data->oy; ! window_copy_scroll_to(wme, px, py); window_copy_cmd_previous_matching_bracket(cs); px = data->cx; --- 1379,1385 ---- sx = data->cx; sy = screen_hsize(s) + data->cy - data->oy; ! window_copy_scroll_to(wme, px, py, 0); window_copy_cmd_previous_matching_bracket(cs); px = data->cx; *************** *** 1385,1391 **** if (gc.data.size == 1 && (~gc.flags & GRID_FLAG_PADDING) && strchr(close, *gc.data.data) != NULL) ! window_copy_scroll_to(wme, sx, sy); break; } --- 1388,1394 ---- if (gc.data.size == 1 && (~gc.flags & GRID_FLAG_PADDING) && strchr(close, *gc.data.data) != NULL) ! window_copy_scroll_to(wme, sx, sy, 0); break; } *************** *** 1447,1453 **** /* Move the cursor to the found location if any. */ if (!failed) ! window_copy_scroll_to(wme, px, py); } return (WINDOW_COPY_CMD_NOTHING); --- 1450,1456 ---- /* Move the cursor to the found location if any. */ if (!failed) ! window_copy_scroll_to(wme, px, py, 0); } return (WINDOW_COPY_CMD_NOTHING); *************** *** 1659,1664 **** --- 1662,1671 ---- struct window_copy_mode_data *data = wme->data; u_int np = wme->prefix; + if (data->searchtime != 0 && + get_timer() - data->searchtime < WINDOW_COPY_SEARCH_REPEAT) + return (WINDOW_COPY_CMD_NOTHING); + if (data->searchtype == WINDOW_COPY_SEARCHUP) { for (; np != 0; np--) window_copy_search_up(wme, data->searchregex); *************** *** 1666,1671 **** --- 1673,1679 ---- for (; np != 0; np--) window_copy_search_down(wme, data->searchregex); } + data->searchtime = get_timer(); return (WINDOW_COPY_CMD_NOTHING); } *************** *** 1676,1681 **** --- 1684,1693 ---- struct window_copy_mode_data *data = wme->data; u_int np = wme->prefix; + if (data->searchtime != 0 && + get_timer() - data->searchtime < WINDOW_COPY_SEARCH_REPEAT) + return (WINDOW_COPY_CMD_NOTHING); + if (data->searchtype == WINDOW_COPY_SEARCHUP) { for (; np != 0; np--) window_copy_search_down(wme, data->searchregex); *************** *** 1683,1688 **** --- 1695,1701 ---- for (; np != 0; np--) window_copy_search_up(wme, data->searchregex); } + data->searchtime = get_timer(); return (WINDOW_COPY_CMD_NOTHING); } *************** *** 2327,2333 **** } static void ! window_copy_scroll_to(struct window_mode_entry *wme, u_int px, u_int py) { struct window_copy_mode_data *data = wme->data; struct grid *gd = data->backing->grid; --- 2340,2347 ---- } static void ! window_copy_scroll_to(struct window_mode_entry *wme, u_int px, u_int py, ! int no_redraw) { struct window_copy_mode_data *data = wme->data; struct grid *gd = data->backing->grid; *************** *** 2352,2361 **** 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_redraw_screen(wme); } static int --- 2366,2376 ---- data->oy = gd->hsize - offset; } ! if (!no_redraw && data->searchmark != NULL && !data->timeout) ! window_copy_search_marks(wme, NULL, data->searchregex, 1); window_copy_update_selection(wme, 1, 0); ! if (!no_redraw) ! window_copy_redraw_screen(wme); } static int *************** *** 2877,2883 **** } if (found) { ! window_copy_scroll_to(wme, px, i); return (1); } if (wrap) { --- 2892,2898 ---- } if (found) { ! window_copy_scroll_to(wme, px, i, 1); return (1); } if (wrap) { *************** *** 2903,2909 **** struct grid *gd = s->grid; const char *str = data->searchstr; u_int fx, fy, endline; ! int wrapflag, cis, found; if (regex && str[strcspn(str, "^$*+()?[].\\")] == '\0') regex = 0; --- 2918,2924 ---- struct grid *gd = s->grid; const char *str = data->searchstr; u_int fx, fy, endline; ! int wrapflag, cis, found, visible_only; if (regex && str[strcspn(str, "^$*+()?[].\\")] == '\0') regex = 0; *************** *** 2911,2916 **** --- 2926,2935 ---- if (data->timeout) return (0); + if (wp->searchstr == NULL || wp->searchregex != regex) + visible_only = 0; + else + visible_only = (strcmp(wp->searchstr, str) == 0); free(wp->searchstr); wp->searchstr = xstrdup(str); wp->searchregex = regex; *************** *** 2936,2958 **** found = window_copy_search_jump(wme, gd, ss.grid, fx, fy, endline, cis, wrapflag, direction, regex); - if (window_copy_search_marks(wme, &ss, regex)) - window_copy_redraw_screen(wme); - screen_free(&ss); return (found); } static int window_copy_search_marks(struct window_mode_entry *wme, struct screen *ssp, ! int regex) { struct window_copy_mode_data *data = wme->data; struct screen *s = data->backing, ss; struct screen_write_ctx ctx; struct grid *gd = s->grid; - const struct grid_line *gl; int found, cis, which = -1, stopped = 0; int cflags = REG_EXTENDED; u_int px, py, i, b, nfound = 0, width; --- 2955,2991 ---- found = window_copy_search_jump(wme, gd, ss.grid, fx, fy, endline, cis, wrapflag, direction, regex); + if (found) + window_copy_search_marks(wme, &ss, regex, visible_only); + window_copy_redraw_screen(wme); screen_free(&ss); return (found); } + static void + window_copy_visible_lines(struct window_copy_mode_data *data, u_int *start, + u_int *end) + { + struct grid *gd = data->backing->grid; + const struct grid_line *gl; + + for (*start = gd->hsize - data->oy; *start > 0; (*start)--) { + gl = grid_peek_line(gd, (*start) - 1); + if (~gl->flags & GRID_LINE_WRAPPED) + break; + } + *end = gd->hsize - data->oy + gd->sy; + } + static int window_copy_search_marks(struct window_mode_entry *wme, struct screen *ssp, ! int regex, int visible_only) { struct window_copy_mode_data *data = wme->data; struct screen *s = data->backing, ss; struct screen_write_ctx ctx; struct grid *gd = s->grid; int found, cis, which = -1, stopped = 0; int cflags = REG_EXTENDED; u_int px, py, i, b, nfound = 0, width; *************** *** 2988,2996 **** } tstart = get_timer(); ! start = 0; ! end = gd->hsize + gd->sy; ! stop = get_timer() + WINDOW_COPY_SEARCH_ALL_TIMEOUT; again: free(data->searchmark); --- 3021,3033 ---- } tstart = get_timer(); ! if (visible_only) ! window_copy_visible_lines(data, &start, &end); ! else { ! start = 0; ! end = gd->hsize + gd->sy; ! stop = get_timer() + WINDOW_COPY_SEARCH_ALL_TIMEOUT; ! } again: free(data->searchmark); *************** *** 3045,3078 **** if (stopped && stop != 0) { /* Try again but just the visible context. */ ! for (start = gd->hsize - data->oy; start > 0; start--) { ! gl = grid_peek_line(gd, start - 1); ! if (~gl->flags & GRID_LINE_WRAPPED) ! break; ! } ! end = gd->hsize - data->oy + gd->sy; stop = 0; goto again; } ! if (stopped) { ! data->searchthis = -1; ! if (nfound > 1000) ! data->searchcount = 1000; ! else if (nfound > 100) ! data->searchcount = 100; ! else if (nfound > 10) ! data->searchcount = 10; ! else ! data->searchcount = -1; ! data->searchmore = 1; ! } else { ! if (which != -1) ! data->searchthis = 1 + nfound - which; ! else data->searchthis = -1; ! data->searchcount = nfound; ! data->searchmore = 0; } out: --- 3082,3112 ---- if (stopped && stop != 0) { /* Try again but just the visible context. */ ! window_copy_visible_lines(data, &start, &end); stop = 0; goto again; } ! if (!visible_only) { ! if (stopped) { data->searchthis = -1; ! if (nfound > 1000) ! data->searchcount = 1000; ! else if (nfound > 100) ! data->searchcount = 100; ! else if (nfound > 10) ! data->searchcount = 10; ! else ! data->searchcount = -1; ! data->searchmore = 1; ! } else { ! if (which != -1) ! data->searchthis = 1 + nfound - which; ! else ! data->searchthis = -1; ! data->searchcount = nfound; ! data->searchmore = 0; ! } } out: *************** *** 4563,4569 **** data->oy -= ny; if (data->searchmark != NULL && !data->timeout) ! window_copy_search_marks(wme, NULL, data->searchregex); window_copy_update_selection(wme, 0, 0); screen_write_start_pane(&ctx, wp, NULL); --- 4597,4603 ---- data->oy -= ny; if (data->searchmark != NULL && !data->timeout) ! window_copy_search_marks(wme, NULL, data->searchregex, 1); window_copy_update_selection(wme, 0, 0); screen_write_start_pane(&ctx, wp, NULL); *************** *** 4599,4605 **** data->oy += ny; if (data->searchmark != NULL && !data->timeout) ! window_copy_search_marks(wme, NULL, data->searchregex); window_copy_update_selection(wme, 0, 0); screen_write_start_pane(&ctx, wp, NULL); --- 4633,4639 ---- data->oy += ny; if (data->searchmark != NULL && !data->timeout) ! window_copy_search_marks(wme, NULL, data->searchregex, 1); window_copy_update_selection(wme, 0, 0); screen_write_start_pane(&ctx, wp, NULL);