mirror of
https://github.com/tmux/tmux.git
synced 2026-10-16 16:44:30 +00:00
Check the column when looking up search marks in case the cursor is past
the last column, GitHub issue 5756 from Alejandro Pacheco.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: window-copy.c,v 1.438 2026/10/13 23:17:42 nicm Exp $ */
|
||||
/* $OpenBSD: window-copy.c,v 1.439 2026/10/16 12:17:03 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
||||
@@ -87,6 +87,8 @@ static int window_copy_last_regex(struct grid *, u_int, u_int, u_int,
|
||||
int);
|
||||
static int window_copy_search_mark_at(struct window_copy_mode_data *,
|
||||
u_int, u_int, u_int *);
|
||||
static int window_copy_search_mark_at_cursor(
|
||||
struct window_copy_mode_data *, u_int *, int *);
|
||||
static int window_copy_grow_searchpos(struct window_copy_mode_data *,
|
||||
u_int, u_int, u_int);
|
||||
static void window_copy_search_set_index(struct window_copy_mode_data *,
|
||||
@@ -5109,6 +5111,8 @@ window_copy_search_mark_at(struct window_copy_mode_data *data, u_int px,
|
||||
struct screen *s = data->backing;
|
||||
struct grid *gd = s->grid;
|
||||
|
||||
if (px >= gd->sx)
|
||||
return (-1);
|
||||
if (py < gd->hsize - data->oy)
|
||||
return (-1);
|
||||
if (py > gd->hsize - data->oy + gd->sy - 1)
|
||||
@@ -5117,6 +5121,23 @@ window_copy_search_mark_at(struct window_copy_mode_data *data, u_int px,
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the search mark position of the cursor. If the cursor is after the last
|
||||
* column, use the last cell and set after.
|
||||
*/
|
||||
static int
|
||||
window_copy_search_mark_at_cursor(struct window_copy_mode_data *data,
|
||||
u_int *at, int *after)
|
||||
{
|
||||
u_int cx = data->cx, cy, sx = screen_size_x(data->backing);
|
||||
|
||||
cy = screen_hsize(data->backing) - data->oy + data->cy;
|
||||
*after = (cx >= sx);
|
||||
if (*after)
|
||||
cx = sx - 1;
|
||||
return (window_copy_search_mark_at(data, cx, cy, at));
|
||||
}
|
||||
|
||||
static u_int
|
||||
window_copy_clip_width(u_int width, u_int b, u_int sx, u_int sy)
|
||||
{
|
||||
@@ -5436,20 +5457,20 @@ window_copy_match_at_cursor(struct window_copy_mode_data *data)
|
||||
{
|
||||
struct grid *gd = data->backing->grid;
|
||||
struct grid_cell gc;
|
||||
u_int at, start, end, cy, px, py;
|
||||
u_int at, start, end, px, py;
|
||||
u_int sx = screen_size_x(data->backing);
|
||||
char *buf = NULL;
|
||||
size_t len = 0;
|
||||
int after;
|
||||
|
||||
if (data->searchmark == NULL)
|
||||
return (NULL);
|
||||
|
||||
cy = screen_hsize(data->backing) - data->oy + data->cy;
|
||||
if (window_copy_search_mark_at(data, data->cx, cy, &at) != 0)
|
||||
if (window_copy_search_mark_at_cursor(data, &at, &after) != 0)
|
||||
return (NULL);
|
||||
if (data->searchmark[at] == 0) {
|
||||
/* Allow one position after the match. */
|
||||
if (at == 0 || data->searchmark[--at] == 0)
|
||||
if (after || at == 0 || data->searchmark[--at] == 0)
|
||||
return (NULL);
|
||||
}
|
||||
window_copy_match_start_end(data, at, &start, &end);
|
||||
@@ -5489,7 +5510,7 @@ window_copy_update_style(struct window_mode_entry *wme, u_int fx, u_int fy,
|
||||
struct window_pane *wp = wme->wp;
|
||||
struct window_copy_mode_data *data = wme->data;
|
||||
u_int mark, start, end, cy, cursor, current;
|
||||
int inv = 0, found = 0;
|
||||
int inv = 0, found = 0, after;
|
||||
int keys;
|
||||
|
||||
cy = screen_hsize(data->backing) - data->oy + data->cy;
|
||||
@@ -5524,16 +5545,16 @@ window_copy_update_style(struct window_mode_entry *wme, u_int fx, u_int fy,
|
||||
if (mark == 0)
|
||||
return;
|
||||
|
||||
if (window_copy_search_mark_at(data, data->cx, cy, &cursor) == 0) {
|
||||
if (window_copy_search_mark_at_cursor(data, &cursor, &after) == 0) {
|
||||
keys = options_get_number(wp->window->options, "mode-keys");
|
||||
if (cursor != 0 &&
|
||||
if ((after || cursor != 0) &&
|
||||
keys == MODEKEY_EMACS &&
|
||||
data->searchdirection) {
|
||||
if (data->searchmark[cursor - 1] == mark) {
|
||||
if (!after)
|
||||
cursor--;
|
||||
if (data->searchmark[cursor] == mark)
|
||||
found = 1;
|
||||
}
|
||||
} else if (data->searchmark[cursor] == mark)
|
||||
} else if (!after && data->searchmark[cursor] == mark)
|
||||
found = 1;
|
||||
if (found) {
|
||||
window_copy_match_start_end(data, cursor, &start, &end);
|
||||
|
||||
Reference in New Issue
Block a user