aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2014-05-23 01:02:34 -0400
committerJesse Luehrs <doy@tozt.net>2014-07-04 22:39:07 -0400
commit492416f5f2a1ab42bc800649be9be9ee289d1abb (patch)
tree99bbd5b431b4ec2e039c8d5fcaae82345e396840
parent6ec13b51502743cd01b18a84eaa8487835e384e0 (diff)
downloadrunes-492416f5f2a1ab42bc800649be9be9ee289d1abb.tar.gz
runes-492416f5f2a1ab42bc800649be9be9ee289d1abb.zip
display selection past the end of a row properly
-rw-r--r--src/screen.c39
1 files 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;
+}