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

@ -306,8 +306,9 @@ window_copy_clone_screen(struct screen *src, struct screen *hint, u_int *cx,
u_int *cy, int trim)
{
struct screen *dst;
u_int sy;
const struct grid_line *gl;
u_int sy, wx, wy;
int reflow;
dst = xcalloc(1, sizeof *dst);
@ -324,6 +325,12 @@ window_copy_clone_screen(struct screen *src, struct screen *hint, u_int *cx,
screen_size_x(src), sy, screen_size_x(hint),
screen_hsize(src) + screen_size_y(src));
screen_init(dst, screen_size_x(src), sy, screen_hlimit(src));
/*
* Ensure history is on for the backing grid so lines are not deleted
* during resizing.
*/
dst->grid->flags |= GRID_HISTORY;
grid_duplicate_lines(dst->grid, 0, src->grid, 0, sy);
dst->grid->sy = sy - screen_hsize(src);
@ -337,8 +344,19 @@ window_copy_clone_screen(struct screen *src, struct screen *hint, u_int *cx,
dst->cy = src->cy;
}
if (cx != NULL && cy != NULL) {
*cx = dst->cx;
*cy = screen_hsize(dst) + dst->cy;
reflow = (screen_size_x(hint) != screen_size_x(dst));
}
else
reflow = 0;
if (reflow)
grid_wrap_position(dst->grid, *cx, *cy, &wx, &wy);
screen_resize_cursor(dst, screen_size_x(hint), screen_size_y(hint), 1,
0, cx, cy);
0, 0);
if (reflow)
grid_unwrap_position(dst->grid, cx, cy, wx, wy);
return (dst);
}
@ -392,13 +410,12 @@ window_copy_init(struct window_mode_entry *wme,
data->backing = window_copy_clone_screen(base, &data->screen, &cx, &cy,
wme->swp != wme->wp);
data->cx = cx;
if (cy < screen_hsize(data->backing)) {
data->cx = cx;
data->cy = 0;
data->oy = screen_hsize(data->backing) - cy;
} else {
data->cx = data->backing->cx;
data->cy = data->backing->cy;
data->cy = cy - screen_hsize(data->backing);
data->oy = 0;
}
@ -731,16 +748,28 @@ window_copy_resize(struct window_mode_entry *wme, u_int sx, u_int sy)
{
struct window_copy_mode_data *data = wme->data;
struct screen *s = &data->screen;
struct grid *gd = data->backing->grid;
u_int cx, cy, wx, wy;
int reflow;
screen_resize(s, sx, sy, 0);
screen_resize_cursor(data->backing, sx, sy, 1, 0, NULL, NULL);
cx = data->cx;
cy = gd->hsize + data->cy - data->oy;
reflow = (gd->sx != sx);
if (reflow)
grid_wrap_position(gd, cx, cy, &wx, &wy);
screen_resize_cursor(data->backing, sx, sy, 1, 0, 0);
if (reflow)
grid_unwrap_position(gd, &cx, &cy, wx, wy);
if (data->cy > sy - 1)
data->cy = sy - 1;
if (data->cx > sx)
data->cx = sx;
if (data->oy > screen_hsize(data->backing))
data->oy = screen_hsize(data->backing);
data->cx = cx;
if (cy < gd->hsize) {
data->cy = 0;
data->oy = gd->hsize - cy;
} else {
data->cy = cy - gd->hsize;
data->oy = 0;
}
window_copy_size_changed(wme);
window_copy_redraw_screen(wme);