Sync OpenBSD patchset 636:

Rectangle copy support, from Robin Lee Powell.
This commit is contained in:
Tiago Cunha
2010-02-08 18:13:17 +00:00
parent a32d095c97
commit 3c37b09272
5 changed files with 187 additions and 64 deletions

115
screen.c
View File

@ -1,4 +1,4 @@
/* $Id: screen.c,v 1.98 2010-01-05 23:54:53 tcunha Exp $ */
/* $Id: screen.c,v 1.99 2010-02-08 18:13:17 tcunha Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -227,41 +227,17 @@ screen_resize_y(struct screen *s, u_int sy)
/* Set selection. */
void
screen_set_selection(struct screen *s,
u_int sx, u_int sy, u_int ex, u_int ey, struct grid_cell *gc)
screen_set_selection(struct screen *s, u_int sx, u_int sy,
u_int ex, u_int ey, u_int rectflag, struct grid_cell *gc)
{
struct screen_sel *sel = &s->sel;
memcpy(&sel->cell, gc, sizeof sel->cell);
sel->flag = 1;
sel->rectflag = rectflag;
/* starting line < ending line -- downward selection. */
if (sy < ey) {
sel->sx = sx; sel->sy = sy;
sel->ex = ex; sel->ey = ey;
return;
}
/* starting line > ending line -- upward selection. */
if (sy > ey) {
if (sx > 0) {
sel->sx = ex; sel->sy = ey;
sel->ex = sx - 1; sel->ey = sy;
} else {
sel->sx = ex; sel->sy = ey;
sel->ex = -1; sel->ey = sy - 1;
}
return;
}
/* starting line == ending line. */
if (ex < sx) {
sel->sx = ex; sel->sy = ey;
sel->ex = sx - 1; sel->ey = sy;
} else {
sel->sx = sx; sel->sy = sy;
sel->ex = ex; sel->ey = ey;
}
sel->sx = sx; sel->sy = sy;
sel->ex = ex; sel->ey = ey;
}
/* Clear selection. */
@ -279,16 +255,81 @@ screen_check_selection(struct screen *s, u_int px, u_int py)
{
struct screen_sel *sel = &s->sel;
if (!sel->flag || py < sel->sy || py > sel->ey)
if (!sel->flag)
return (0);
if (py == sel->sy && py == sel->ey) {
if (px < sel->sx || px > sel->ex)
return (0);
return (1);
if (sel->rectflag) {
if (sel->sy < sel->ey) {
/* start line < end line -- downward selection. */
if (py < sel->sy || py > sel->ey)
return (0);
} else if (sel->sy > sel->ey) {
/* start line > end line -- upward selection. */
if (py > sel->sy || py < sel->ey)
return (0);
} else {
/* starting line == ending line. */
if (py != sel->sy)
return (0);
}
/*
* Need to include the selection start row, but not the cursor
* row, which means the selection changes depending on which
* one is on the left.
*/
if (sel->ex < sel->sx) {
/* Cursor (ex) is on the left. */
if (px <= sel->ex)
return (0);
if (px > sel->sx)
return (0);
} else {
/* Selection start (sx) is on the left. */
if (px < sel->sx)
return (0);
if (px >= sel->ex)
return (0);
}
} else {
/*
* Like emacs, keep the top-left-most character, and drop the
* bottom-right-most, regardless of copy direction.
*/
if (sel->sy < sel->ey) {
/* starting line < ending line -- downward selection. */
if (py < sel->sy || py > sel->ey)
return (0);
if ((py == sel->sy && px < sel->sx)
|| (py == sel->ey && px > sel->ex))
return (0);
} else if (sel->sy > sel->ey) {
/* starting line > ending line -- upward selection. */
if (py > sel->sy || py < sel->ey)
return (0);
if ((py == sel->sy && px >= sel->sx)
|| (py == sel->ey && px < sel->ex))
return (0);
} else {
/* starting line == ending line. */
if (py != sel->sy)
return (0);
if (sel->ex < sel->sx) {
/* cursor (ex) is on the left */
if (px > sel->sx || px < sel->ex)
return (0);
} else {
/* selection start (sx) is on the left */
if (px < sel->sx || px > sel->ex)
return (0);
}
}
}
if ((py == sel->sy && px < sel->sx) || (py == sel->ey && px > sel->ex))
return (0);
return (1);
}