Skip to content

Commit f48c46a

Browse files
committed
Fix rectangle selection, from Anindya Mukherjee, GitHub issue 2709.
1 parent f06ee2b commit f48c46a

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

window-copy.c

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,10 +1102,13 @@ static enum window_copy_cmd_action
11021102
window_copy_cmd_cursor_right(struct window_copy_cmd_state *cs)
11031103
{
11041104
struct window_mode_entry *wme = cs->wme;
1105+
struct window_copy_mode_data *data = wme->data;
11051106
u_int np = wme->prefix;
11061107

1107-
for (; np != 0; np--)
1108-
window_copy_cursor_right(wme, 0);
1108+
for (; np != 0; np--) {
1109+
window_copy_cursor_right(wme, data->screen.sel != NULL &&
1110+
data->rectflag);
1111+
}
11091112
return (WINDOW_COPY_CMD_NOTHING);
11101113
}
11111114

@@ -4425,10 +4428,12 @@ window_copy_cursor_up(struct window_mode_entry *wme, int scroll_only)
44254428
struct window_copy_mode_data *data = wme->data;
44264429
struct screen *s = &data->screen;
44274430
u_int ox, oy, px, py;
4431+
int norectsel;
44284432

4433+
norectsel = data->screen.sel == NULL || !data->rectflag;
44294434
oy = screen_hsize(data->backing) + data->cy - data->oy;
44304435
ox = window_copy_find_length(wme, oy);
4431-
if (data->cx != ox) {
4436+
if (norectsel && data->cx != ox) {
44324437
data->lastcx = data->cx;
44334438
data->lastsx = ox;
44344439
}
@@ -4437,7 +4442,8 @@ window_copy_cursor_up(struct window_mode_entry *wme, int scroll_only)
44374442
window_copy_other_end(wme);
44384443

44394444
if (scroll_only || data->cy == 0) {
4440-
data->cx = data->lastcx;
4445+
if (norectsel)
4446+
data->cx = data->lastcx;
44414447
window_copy_scroll_down(wme, 1);
44424448
if (scroll_only) {
44434449
if (data->cy == screen_size_y(s) - 1)
@@ -4446,7 +4452,11 @@ window_copy_cursor_up(struct window_mode_entry *wme, int scroll_only)
44464452
window_copy_redraw_lines(wme, data->cy, 2);
44474453
}
44484454
} else {
4449-
window_copy_update_cursor(wme, data->lastcx, data->cy - 1);
4455+
if (norectsel) {
4456+
window_copy_update_cursor(wme, data->lastcx,
4457+
data->cy - 1);
4458+
} else
4459+
window_copy_update_cursor(wme, data->cx, data->cy - 1);
44504460
if (window_copy_update_selection(wme, 1, 0)) {
44514461
if (data->cy == screen_size_y(s) - 1)
44524462
window_copy_redraw_lines(wme, data->cy, 1);
@@ -4455,7 +4465,7 @@ window_copy_cursor_up(struct window_mode_entry *wme, int scroll_only)
44554465
}
44564466
}
44574467

4458-
if (data->screen.sel == NULL || !data->rectflag) {
4468+
if (norectsel) {
44594469
py = screen_hsize(data->backing) + data->cy - data->oy;
44604470
px = window_copy_find_length(wme, py);
44614471
if ((data->cx >= data->lastsx && data->cx != px) ||
@@ -4492,10 +4502,12 @@ window_copy_cursor_down(struct window_mode_entry *wme, int scroll_only)
44924502
struct window_copy_mode_data *data = wme->data;
44934503
struct screen *s = &data->screen;
44944504
u_int ox, oy, px, py;
4505+
int norectsel;
44954506

4507+
norectsel = data->screen.sel == NULL || !data->rectflag;
44964508
oy = screen_hsize(data->backing) + data->cy - data->oy;
44974509
ox = window_copy_find_length(wme, oy);
4498-
if (data->cx != ox) {
4510+
if (norectsel && data->cx != ox) {
44994511
data->lastcx = data->cx;
45004512
data->lastsx = ox;
45014513
}
@@ -4504,17 +4516,22 @@ window_copy_cursor_down(struct window_mode_entry *wme, int scroll_only)
45044516
window_copy_other_end(wme);
45054517

45064518
if (scroll_only || data->cy == screen_size_y(s) - 1) {
4507-
data->cx = data->lastcx;
4519+
if (norectsel)
4520+
data->cx = data->lastcx;
45084521
window_copy_scroll_up(wme, 1);
45094522
if (scroll_only && data->cy > 0)
45104523
window_copy_redraw_lines(wme, data->cy - 1, 2);
45114524
} else {
4512-
window_copy_update_cursor(wme, data->lastcx, data->cy + 1);
4525+
if (norectsel) {
4526+
window_copy_update_cursor(wme, data->lastcx,
4527+
data->cy + 1);
4528+
} else
4529+
window_copy_update_cursor(wme, data->cx, data->cy + 1);
45134530
if (window_copy_update_selection(wme, 1, 0))
45144531
window_copy_redraw_lines(wme, data->cy - 1, 2);
45154532
}
45164533

4517-
if (data->screen.sel == NULL || !data->rectflag) {
4534+
if (norectsel) {
45184535
py = screen_hsize(data->backing) + data->cy - data->oy;
45194536
px = window_copy_find_length(wme, py);
45204537
if ((data->cx >= data->lastsx && data->cx != px) ||

0 commit comments

Comments
 (0)