Store and restore cursor position when copy mode is resized, from

Anindya Mukherjee.
This commit is contained in:
nicm
2020-05-16 15:49:20 +00:00
parent daa95810b5
commit 6ea6d46d0a
4 changed files with 70 additions and 40 deletions

View File

@ -49,7 +49,7 @@ struct screen_title_entry {
TAILQ_HEAD(screen_titles, screen_title_entry);
static void screen_resize_y(struct screen *, u_int, int, u_int *);
static void screen_reflow(struct screen *, u_int, u_int *, u_int *);
static void screen_reflow(struct screen *, u_int, u_int *, u_int *, int);
/* Free titles stack. */
static void
@ -220,27 +220,19 @@ screen_pop_title(struct screen *s)
}
}
/* Resize screen and return cursor position. */
/* Resize screen with options. */
void
screen_resize_cursor(struct screen *s, u_int sx, u_int sy, int reflow,
int eat_empty, u_int *cx, u_int *cy)
int eat_empty, int cursor)
{
u_int tcx, tcy;
u_int cx = s->cx, cy = s->grid->hsize + s->cy;
if (s->write_list != NULL)
screen_write_free_list(s);
if (cx == NULL)
cx = &tcx;
*cx = s->cx;
if (cy == NULL)
cy = т
*cy = s->grid->hsize + s->cy;
log_debug("%s: new size %ux%u, now %ux%u (cursor %u,%u = %u,%u)",
__func__, sx, sy, screen_size_x(s), screen_size_y(s), s->cx, s->cy,
*cx, *cy);
cx, cy);
if (sx < 1)
sx = 1;
@ -254,20 +246,21 @@ screen_resize_cursor(struct screen *s, u_int sx, u_int sy, int reflow,
reflow = 0;
if (sy != screen_size_y(s))
screen_resize_y(s, sy, eat_empty, cy);
screen_resize_y(s, sy, eat_empty, &cy);
if (reflow)
screen_reflow(s, sx, cx, cy);
screen_reflow(s, sx, &cx, &cy, cursor);
if (*cy >= s->grid->hsize) {
s->cx = *cx;
s->cy = (*cy) - s->grid->hsize;
if (cy >= s->grid->hsize) {
s->cx = cx;
s->cy = cy - s->grid->hsize;
} else {
s->cx = 0;
s->cy = 0;
}
log_debug("%s: cursor finished at %u,%u = %u,%u", __func__, s->cx,
s->cy, *cx, *cy);
s->cy, cx, cy);
if (s->write_list != NULL)
screen_write_make_list(s);
@ -277,7 +270,7 @@ screen_resize_cursor(struct screen *s, u_int sx, u_int sy, int reflow,
void
screen_resize(struct screen *s, u_int sx, u_int sy, int reflow)
{
screen_resize_cursor(s, sx, sy, reflow, 1, NULL, NULL);
screen_resize_cursor(s, sx, sy, reflow, 1, 1);
}
static void
@ -525,17 +518,26 @@ screen_select_cell(struct screen *s, struct grid_cell *dst,
/* Reflow wrapped lines. */
static void
screen_reflow(struct screen *s, u_int new_x, u_int *cx, u_int *cy)
screen_reflow(struct screen *s, u_int new_x, u_int *cx, u_int *cy, int cursor)
{
u_int wx, wy;
grid_wrap_position(s->grid, *cx, *cy, &wx, &wy);
log_debug("%s: cursor %u,%u is %u,%u", __func__, *cx, *cy, wx, wy);
if (cursor) {
grid_wrap_position(s->grid, *cx, *cy, &wx, &wy);
log_debug("%s: cursor %u,%u is %u,%u", __func__, *cx, *cy, wx,
wy);
}
grid_reflow(s->grid, new_x);
grid_unwrap_position(s->grid, cx, cy, wx, wy);
log_debug("%s: new cursor is %u,%u", __func__, *cx,* cy);
if (cursor) {
grid_unwrap_position(s->grid, cx, cy, wx, wy);
log_debug("%s: new cursor is %u,%u", __func__, *cx, *cy);
}
else {
*cx = 0;
*cy = s->grid->hsize;
}
}
/*