summaryrefslogtreecommitdiff
path: root/usr.bin/tmux/window-copy.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/tmux/window-copy.c')
-rw-r--r--usr.bin/tmux/window-copy.c63
1 files changed, 46 insertions, 17 deletions
diff --git a/usr.bin/tmux/window-copy.c b/usr.bin/tmux/window-copy.c
index 148b32f5189..1a6c6690705 100644
--- a/usr.bin/tmux/window-copy.c
+++ b/usr.bin/tmux/window-copy.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window-copy.c,v 1.363 2024/11/05 09:41:17 nicm Exp $ */
+/* $OpenBSD: window-copy.c,v 1.364 2024/11/08 08:51:36 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -3098,14 +3098,16 @@ static int
window_copy_search_lr(struct grid *gd, struct grid *sgd, u_int *ppx, u_int py,
u_int first, u_int last, int cis)
{
- u_int ax, bx, px, pywrap, endline;
+ u_int ax, bx, px, pywrap, endline, padding;
int matched;
struct grid_line *gl;
+ struct grid_cell gc;
endline = gd->hsize + gd->sy - 1;
for (ax = first; ax < last; ax++) {
+ padding = 0;
for (bx = 0; bx < sgd->sx; bx++) {
- px = ax + bx;
+ px = ax + bx + padding;
pywrap = py;
/* Wrap line. */
while (px >= gd->sx && pywrap < endline) {
@@ -3116,8 +3118,13 @@ window_copy_search_lr(struct grid *gd, struct grid *sgd, u_int *ppx, u_int py,
pywrap++;
}
/* We have run off the end of the grid. */
- if (px >= gd->sx)
+ if (px - padding >= gd->sx)
break;
+
+ grid_get_cell(gd, px, pywrap, &gc);
+ if (gc.flags & GRID_FLAG_TAB)
+ padding += gc.data.width - 1;
+
matched = window_copy_search_compare(gd, px, pywrap,
sgd, bx, cis);
if (!matched)
@@ -3135,14 +3142,16 @@ static int
window_copy_search_rl(struct grid *gd,
struct grid *sgd, u_int *ppx, u_int py, u_int first, u_int last, int cis)
{
- u_int ax, bx, px, pywrap, endline;
+ u_int ax, bx, px, pywrap, endline, padding;
int matched;
struct grid_line *gl;
+ struct grid_cell gc;
endline = gd->hsize + gd->sy - 1;
for (ax = last; ax > first; ax--) {
+ padding = 0;
for (bx = 0; bx < sgd->sx; bx++) {
- px = ax - 1 + bx;
+ px = ax - 1 + bx + padding;
pywrap = py;
/* Wrap line. */
while (px >= gd->sx && pywrap < endline) {
@@ -3153,8 +3162,13 @@ window_copy_search_rl(struct grid *gd,
pywrap++;
}
/* We have run off the end of the grid. */
- if (px >= gd->sx)
+ if (px - padding >= gd->sx)
break;
+
+ grid_get_cell(gd, px, pywrap, &gc);
+ if (gc.flags & GRID_FLAG_TAB)
+ padding += gc.data.width - 1;
+
matched = window_copy_search_compare(gd, px, pywrap,
sgd, bx, cis);
if (!matched)
@@ -3875,10 +3889,12 @@ window_copy_search_marks(struct window_mode_entry *wme, struct screen *ssp,
struct screen *s = data->backing, ss;
struct screen_write_ctx ctx;
struct grid *gd = s->grid;
+ struct grid_cell gc;
int found, cis, stopped = 0;
int cflags = REG_EXTENDED;
- u_int px, py, i, b, nfound = 0, width;
- u_int ssize = 1, start, end;
+ u_int px, py, i, b, nfound = 0, width, tw;
+ u_int ssize = 1, start, end, sx = gd->sx;
+ u_int sy = gd->sy;
char *sbuf;
regex_t reg;
uint64_t stop = 0, tstart, t;
@@ -3915,13 +3931,13 @@ window_copy_search_marks(struct window_mode_entry *wme, struct screen *ssp,
window_copy_visible_lines(data, &start, &end);
else {
start = 0;
- end = gd->hsize + gd->sy;
+ end = gd->hsize + sy;
stop = get_timer() + WINDOW_COPY_SEARCH_ALL_TIMEOUT;
}
again:
free(data->searchmark);
- data->searchmark = xcalloc(gd->sx, gd->sy);
+ data->searchmark = xcalloc(sx, sy);
data->searchgen = 1;
for (py = start; py < end; py++) {
@@ -3929,21 +3945,34 @@ again:
for (;;) {
if (regex) {
found = window_copy_search_lr_regex(gd,
- &px, &width, py, px, gd->sx, &reg);
+ &px, &width, py, px, sx, &reg);
+ grid_get_cell(gd, px + width - 1, py, &gc);
+ if (gc.data.width > 2)
+ width += gc.data.width - 1;
if (!found)
break;
} else {
found = window_copy_search_lr(gd, ssp->grid,
- &px, py, px, gd->sx, cis);
+ &px, py, px, sx, cis);
if (!found)
break;
}
nfound++;
+ tw = width;
if (window_copy_search_mark_at(data, px, py, &b) == 0) {
- if (b + width > gd->sx * gd->sy)
- width = (gd->sx * gd->sy) - b;
- for (i = b; i < b + width; i++) {
+ if (b + width > sx * sy)
+ width = (sx * sy) - b;
+ tw = width;
+ for (i = b; i < b + tw; i++) {
+ if (!regex) {
+ grid_get_cell(gd, px + (i - b),
+ py, &gc);
+ if (gc.flags & GRID_FLAG_TAB)
+ tw += gc.data.width - 1;
+ if (b + tw > sx * sy)
+ tw = (sx * sy) - b;
+ }
if (data->searchmark[i] != 0)
continue;
data->searchmark[i] = data->searchgen;
@@ -3953,7 +3982,7 @@ again:
else
data->searchgen++;
}
- px += width;
+ px += tw;
}
t = get_timer();