mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
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.
This commit is contained in:
parent
b647aa447b
commit
38c050746d
3 changed files with 37 additions and 15 deletions
28
selection.c
28
selection.c
|
|
@ -30,17 +30,37 @@ selection_enabled(const struct terminal *term)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
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)
|
if (term->selection.start.row == -1 || term->selection.end.row == -1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const struct coord *start = &term->selection.start;
|
const struct coord *start = &term->selection.start;
|
||||||
const struct coord *end = &term->selection.end;
|
const struct coord *end = &term->selection.end;
|
||||||
assert(start->row <= end->row);
|
|
||||||
|
|
||||||
row_no += term->grid->view;
|
if (start->row > end->row) {
|
||||||
return row_no >= start->row && row_no <= 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
|
static void
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ void selection_finalize(struct terminal *term, uint32_t serial);
|
||||||
void selection_cancel(struct terminal *term);
|
void selection_cancel(struct terminal *term);
|
||||||
void selection_extend(struct terminal *term, int col, int row, uint32_t serial);
|
void selection_extend(struct terminal *term, int col, int row, uint32_t serial);
|
||||||
|
|
||||||
bool selection_on_row_in_view(const struct terminal *term, int row_no);
|
bool selection_on_rows_in_view(const struct terminal *term, int start, int end);
|
||||||
|
|
||||||
void selection_mark_word(struct terminal *term, int col, int row,
|
void selection_mark_word(struct terminal *term, int col, int row,
|
||||||
bool spaces_only, uint32_t serial);
|
bool spaces_only, uint32_t serial);
|
||||||
|
|
|
||||||
22
terminal.c
22
terminal.c
|
|
@ -1750,13 +1750,14 @@ term_scroll_partial(struct terminal *term, struct scroll_region region, int rows
|
||||||
for (int i = term->rows - 1; i >= region.end; i--)
|
for (int i = term->rows - 1; i >= region.end; i--)
|
||||||
grid_swap_row(term->grid, i - rows, i, false);
|
grid_swap_row(term->grid, i - rows, i, false);
|
||||||
|
|
||||||
|
const int begin_scrolled_in = max(region.end - rows, region.start);
|
||||||
|
|
||||||
/* Erase scrolled in lines */
|
/* Erase scrolled in lines */
|
||||||
for (int r = max(region.end - rows, region.start); r < region.end; r++) {
|
for (int r = begin_scrolled_in; r < region.end; r++)
|
||||||
erase_line(term, grid_row_and_alloc(term->grid, r));
|
erase_line(term, grid_row_and_alloc(term->grid, r));
|
||||||
//sixel_delete_at_row(term, r);
|
|
||||||
if (selection_on_row_in_view(term, r))
|
if (selection_on_rows_in_view(term, begin_scrolled_in, region.end - 1))
|
||||||
selection_cancel(term);
|
selection_cancel(term);
|
||||||
}
|
|
||||||
|
|
||||||
sixel_delete_in_range(term, max(region.end - rows, region.start), region.end - 1);
|
sixel_delete_in_range(term, max(region.end - rows, region.start), region.end - 1);
|
||||||
term_damage_scroll(term, DAMAGE_SCROLL, region, rows);
|
term_damage_scroll(term, DAMAGE_SCROLL, region, rows);
|
||||||
|
|
@ -1803,13 +1804,14 @@ term_scroll_reverse_partial(struct terminal *term,
|
||||||
for (int i = 0 + rows; i < region.start + rows; i++)
|
for (int i = 0 + rows; i < region.start + rows; i++)
|
||||||
grid_swap_row(term->grid, i, i - rows, false);
|
grid_swap_row(term->grid, i, i - rows, false);
|
||||||
|
|
||||||
|
const int end_scrolled_in = min(region.start + rows, region.end);
|
||||||
|
|
||||||
/* Erase scrolled in lines */
|
/* Erase scrolled in lines */
|
||||||
for (int r = region.start; r < min(region.start + rows, region.end); r++) {
|
for (int r = region.start; r < end_scrolled_in; r++)
|
||||||
erase_line(term, grid_row_and_alloc(term->grid, r));
|
erase_line(term, grid_row_and_alloc(term->grid, r));
|
||||||
//sixel_delete_at_row(term, r);
|
|
||||||
if (selection_on_row_in_view(term, r))
|
if (selection_on_rows_in_view(term, region.start, end_scrolled_in - 1))
|
||||||
selection_cancel(term);
|
selection_cancel(term);
|
||||||
}
|
|
||||||
|
|
||||||
sixel_delete_in_range(term, region.start, min(region.start + rows, region.end) - 1);
|
sixel_delete_in_range(term, region.start, min(region.start + rows, region.end) - 1);
|
||||||
term_damage_scroll(term, DAMAGE_SCROLL_REVERSE, region, rows);
|
term_damage_scroll(term, DAMAGE_SCROLL_REVERSE, region, rows);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue