=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/grid.c,v retrieving revision 1.92 retrieving revision 1.93 diff -c -r1.92 -r1.93 *** src/usr.bin/tmux/grid.c 2019/04/01 19:33:38 1.92 --- src/usr.bin/tmux/grid.c 2019/04/02 08:45:32 1.93 *************** *** 1,4 **** ! /* $OpenBSD: grid.c,v 1.92 2019/04/01 19:33:38 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: grid.c,v 1.93 2019/04/02 08:45:32 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott *************** *** 1291,1330 **** free(target); } ! /* Convert point position to offset from the start of the grid. */ ! u_int ! grid_to_offset(struct grid *gd, u_int px, u_int py) { ! u_int yy, offset = 0; ! if (py > gd->hsize + gd->sy - 1) { ! px = UINT_MAX; ! py = gd->hsize + gd->sy - 1; } ! ! for (yy = 0; yy < py; yy++) ! offset += gd->linedata[yy].cellused; ! if (px > gd->linedata[yy].cellused) ! px = gd->linedata[yy].cellused; ! return (offset + px); } ! /* Convert offset from the start of the grid to point position. */ void ! grid_from_offset(struct grid *gd, u_int offset, u_int *px, u_int *py) { ! u_int yy; - *px = *py = 0; - for (yy = 0; yy < gd->hsize + gd->sy - 1; yy++) { ! if (offset <= gd->linedata[yy].cellused) break; ! offset -= gd->linedata[yy].cellused; } ! if (offset < gd->linedata[yy].cellused) ! *px = offset; ! else ! *px = gd->linedata[yy].cellused; *py = yy; } --- 1291,1351 ---- free(target); } ! /* Convert to position based on wrapped lines. */ ! void ! grid_wrap_position(struct grid *gd, u_int px, u_int py, u_int *wx, u_int *wy) { ! u_int ax = 0, ay = 0, yy; ! for (yy = 0; yy < py; yy++) { ! if (gd->linedata[yy].flags & GRID_LINE_WRAPPED) ! ax += gd->linedata[yy].cellused; ! else { ! ax = 0; ! ay++; ! } } ! if (px >= gd->linedata[yy].cellused) ! ax = UINT_MAX; ! else ! ax += px; ! *wx = ax; ! *wy = ay; } ! /* Convert position based on wrapped lines back. */ void ! grid_unwrap_position(struct grid *gd, u_int *px, u_int *py, u_int wx, u_int wy) { ! u_int yy, ax = 0, ay = 0; for (yy = 0; yy < gd->hsize + gd->sy - 1; yy++) { ! if (ay == wy) break; ! if (gd->linedata[yy].flags & GRID_LINE_WRAPPED) ! ax += gd->linedata[yy].cellused; ! else { ! ax = 0; ! ay++; ! } } ! ! /* ! * yy is now 0 on the unwrapped line which contains wx. Walk forwards ! * until we find the end or the line now containing wx. ! */ ! if (wx == UINT_MAX) { ! while (gd->linedata[yy].flags & GRID_LINE_WRAPPED) ! yy++; ! wx = gd->linedata[yy].cellused; ! } else { ! while (gd->linedata[yy].flags & GRID_LINE_WRAPPED) { ! if (wx < gd->linedata[yy].cellused) ! break; ! wx -= gd->linedata[yy].cellused; ! yy++; ! } ! } ! *px = wx; *py = yy; }