=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/grid-reader.c,v retrieving revision 1.1 retrieving revision 1.2 diff -c -r1.1 -r1.2 *** src/usr.bin/tmux/grid-reader.c 2020/12/22 09:22:14 1.1 --- src/usr.bin/tmux/grid-reader.c 2021/02/22 06:53:04 1.2 *************** *** 1,4 **** ! /* $OpenBSD: grid-reader.c,v 1.1 2020/12/22 09:22:14 nicm Exp $ */ /* * Copyright (c) 2020 Anindya Mukherjee --- 1,4 ---- ! /* $OpenBSD: grid-reader.c,v 1.2 2021/02/22 06:53:04 nicm Exp $ */ /* * Copyright (c) 2020 Anindya Mukherjee *************** *** 17,22 **** --- 17,23 ---- */ #include "tmux.h" + #include /* Initialise virtual cursor. */ void *************** *** 300,303 **** --- 301,365 ---- } while (!grid_reader_in_set(gr, separators)); gr->cx = oldx; gr->cy = oldy; + } + + /* Jump forward to character. */ + int + grid_reader_cursor_jump(struct grid_reader *gr, const struct utf8_data *jc) + { + struct grid_cell gc; + u_int px, py, xx, yy; + + px = gr->cx; + yy = gr->gd->hsize + gr->gd->sy - 1; + + for (py = gr->cy; py <= yy; py++) { + xx = grid_line_length(gr->gd, py); + while (px < xx) { + grid_get_cell(gr->gd, px, py, &gc); + if (!(gc.flags & GRID_FLAG_PADDING) && + gc.data.size == jc->size && + memcmp(gc.data.data, jc->data, gc.data.size) == 0) { + gr->cx = px; + gr->cy = py; + return 1; + } + px++; + } + + if (py == yy || + !(grid_get_line(gr->gd, py)->flags & GRID_LINE_WRAPPED)) + return 0; + px = 0; + } + return 0; + } + + /* Jump back to character. */ + int + grid_reader_cursor_jump_back(struct grid_reader *gr, const struct utf8_data *jc) + { + struct grid_cell gc; + u_int px, py, xx; + + xx = gr->cx + 1; + + for (py = gr->cy + 1; py > 0; py--) { + for (px = xx; px > 0; px--) { + grid_get_cell(gr->gd, px - 1, py - 1, &gc); + if (!(gc.flags & GRID_FLAG_PADDING) && + gc.data.size == jc->size && + memcmp(gc.data.data, jc->data, gc.data.size) == 0) { + gr->cx = px - 1; + gr->cy = py - 1; + return 1; + } + } + + if (py == 1 || + !(grid_get_line(gr->gd, py - 2)->flags & GRID_LINE_WRAPPED)) + return 0; + xx = grid_line_length(gr->gd, py - 2); + } + return 0; }