aboutsummaryrefslogtreecommitdiff
path: root/selection.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-05-16 14:28:32 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-05-16 19:16:11 +0000
commit38c050746dba0b309780862bf90db43d143b2f0a (patch)
tree6fbcd4810f16f1bb892bcef2ad8d9dd09af8e00c /selection.c
parentrender: only apply transparency to the default background color (diff)
selection: on_row_in_view() -> on_rows_in_view(), and now takes a range
This allows us to check the selection once when scrolling, instead of once for each scrolled in line.
Diffstat (limited to 'selection.c')
-rw-r--r--selection.c28
1 files changed, 24 insertions, 4 deletions
diff --git a/selection.c b/selection.c
index af52e4b5..26c17b87 100644
--- a/selection.c
+++ b/selection.c
@@ -30,17 +30,37 @@ selection_enabled(const struct terminal *term)
}
bool
-selection_on_row_in_view(const struct terminal *term, int row_no)
+selection_on_rows_in_view(const struct terminal *term, int row_start, int row_end)
{
+ LOG_DBG("selection: %d-%d, range: %d-%d (view=%d)",
+ term->selection.start.row, term->selection.end.row,
+ row_start, row_end, term->grid->view);
+
if (term->selection.start.row == -1 || term->selection.end.row == -1)
return false;
const struct coord *start = &term->selection.start;
const struct coord *end = &term->selection.end;
- assert(start->row <= end->row);
- row_no += term->grid->view;
- return row_no >= start->row && row_no <= end->row;
+ if (start->row > end->row) {
+ const struct coord *tmp = start;
+ start = end;
+ end = tmp;
+ }
+
+ row_start += term->grid->view;
+ row_end += term->grid->view;
+
+ if (row_start <= start->row && row_end >= end->row) {
+ /* Row range completely encompases the selection */
+ return true;
+ }
+
+ else if (row_start >= start->row || row_end <= end->row)
+ return true;
+
+ else
+ return false;
}
static void