From 47d6bb74178f446e1bc152816b1f55cbf8912c92 Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Fri, 5 Oct 2012 13:55:29 +0200 Subject: [PATCH] tsm: screen: fix including final character in selection We need to draw the final character of a selection with inversed background, too. This is a bit tricky as the selection may be inversed itself. Therefore, we just keep a flag that tells us whether the previous character was selected and just draw the new character also selected. Signed-off-by: David Herrmann --- src/tsm_screen.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/tsm_screen.c b/src/tsm_screen.c index 81305bd..32f9417 100644 --- a/src/tsm_screen.c +++ b/src/tsm_screen.c @@ -1438,6 +1438,7 @@ void tsm_screen_draw(struct tsm_screen *con, size_t len; struct cell empty; bool in_sel = false, sel_start = false, sel_end = false; + bool was_sel = false; if (!con || !draw_cb) return; @@ -1514,6 +1515,8 @@ void tsm_screen_draw(struct tsm_screen *con, sel_end = true; else sel_end = false; + + was_sel = false; } for (j = 0; j < con->size_x; ++j) { @@ -1525,11 +1528,15 @@ void tsm_screen_draw(struct tsm_screen *con, if (con->sel_active) { if (sel_start && - j == con->sel_start.x) + j == con->sel_start.x) { + was_sel = in_sel; in_sel = !in_sel; + } if (sel_end && - j == con->sel_end.x) + j == con->sel_end.x) { + was_sel = in_sel; in_sel = !in_sel; + } } if (k == cur_y + 1 && @@ -1546,8 +1553,10 @@ void tsm_screen_draw(struct tsm_screen *con, if (con->flags & TSM_SCREEN_INVERSE) attr.inverse = !attr.inverse; - if (in_sel) + if (in_sel || was_sel) { + was_sel = false; attr.inverse = !attr.inverse; + } ch = tsm_symbol_get(NULL, &cell->ch, &len); if (cell->ch == ' ' || cell->ch == 0)