From 492416f5f2a1ab42bc800649be9be9ee289d1abb Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Fri, 23 May 2014 01:02:34 -0400 Subject: display selection past the end of a row properly --- src/screen.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/src/screen.c b/src/screen.c index ccd3752..a24d114 100644 --- a/src/screen.c +++ b/src/screen.c @@ -13,6 +13,7 @@ static int runes_screen_scroll_region_is_active(RunesTerm *t); static int runes_screen_loc_is_between( RunesTerm *t, struct runes_loc loc, struct runes_loc start, struct runes_loc end); +static int runes_screen_row_max_col(RunesTerm *t, int row); void runes_screen_init(RunesTerm *t) { @@ -101,13 +102,32 @@ void runes_screen_process_string(RunesTerm *t, char *buf, size_t len) int runes_screen_loc_is_selected(RunesTerm *t, struct runes_loc loc) { RunesScreen *scr = &t->scr; + struct runes_loc start = scr->grid->selection_start; + struct runes_loc end = scr->grid->selection_end; if (!scr->has_selection) { return 0; } - return runes_screen_loc_is_between( - t, loc, scr->grid->selection_start, scr->grid->selection_end); + if (loc.row == start.row) { + int start_max_col; + + start_max_col = runes_screen_row_max_col(t, start.row); + if (start.col > start_max_col) { + start.col = scr->grid->max.col; + } + } + + if (loc.row == end.row) { + int end_max_col; + + end_max_col = runes_screen_row_max_col(t, end.row); + if (end.col > end_max_col) { + end.col = scr->grid->max.col; + } + } + + return runes_screen_loc_is_between(t, loc, start, end); } void runes_screen_get_string( @@ -989,3 +1009,18 @@ static int runes_screen_loc_is_between( return 1; } + +static int runes_screen_row_max_col(RunesTerm *t, int row) +{ + RunesScreen *scr = &t->scr; + struct runes_cell *cells = scr->grid->rows[row].cells; + int i, max = -1; + + for (i = 0; i < scr->grid->max.col; ++i) { + if (cells[i].len) { + max = i; + } + } + + return max + 1; +} -- cgit v1.2.3-54-g00ecf