summaryrefslogtreecommitdiffstats
path: root/screen.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2007-11-22 19:17:01 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2007-11-22 19:17:01 +0000
commit7ab0b466fe38835cc92f28fed490d7f6ca1a3b5c (patch)
treecb27c5d2b6f1774db80d1458a69f2fc9073e7754 /screen.c
parent18d72e69289fa3dbdb0766ea7f9c0ff8908626b9 (diff)
Text selection with C-space.
Diffstat (limited to 'screen.c')
-rw-r--r--screen.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/screen.c b/screen.c
index 2e1f4a86..c829d062 100644
--- a/screen.c
+++ b/screen.c
@@ -1,4 +1,4 @@
-/* $Id: screen.c,v 1.37 2007-11-22 18:09:43 nicm Exp $ */
+/* $Id: screen.c,v 1.38 2007-11-22 19:17:01 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -278,6 +278,8 @@ screen_draw_start(struct screen_draw_ctx *ctx,
ctx->cx = s->cx;
ctx->cy = s->cy;
+ memset(&ctx->sel, 0, sizeof ctx->sel);
+
ctx->attr = s->attr;
ctx->colr = s->colr;
@@ -285,6 +287,32 @@ screen_draw_start(struct screen_draw_ctx *ctx,
input_store_zero(b, CODE_CURSOROFF);
}
+/* Check if cell in selection. */
+int
+screen_check_selection(struct screen_draw_ctx *ctx, u_int px, u_int py)
+{
+ struct screen_draw_sel *sel = &ctx->sel;
+ u_int xx, yy;
+
+ if (!sel->flag)
+ return (0);
+
+ if (sel->ey < sel->sy) {
+ xx = sel->sx;
+ yy = sel->sy;
+ sel->sx = sel->ex;
+ sel->sy = sel->ey;
+ sel->ex = xx;
+ sel->ey = yy;
+ }
+
+ if (py < sel->sy || py > sel->ey)
+ return (0);
+ if ((py == sel->sy && px < sel->sx) || (py == sel->ey && px > sel->ex))
+ return (0);
+ return (1);
+}
+
/* Get cell data during drawing. */
void
screen_draw_get_cell(struct screen_draw_ctx *ctx,
@@ -297,6 +325,9 @@ screen_draw_get_cell(struct screen_draw_ctx *ctx,
cy = screen_y(s, py) - ctx->oy;
screen_get_cell(s, cx, cy, data, attr, colr);
+
+ if (screen_check_selection(ctx, cx, cy))
+ *attr |= ATTR_REVERSE;
}
/* Finalise drawing. */