mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-04 04:06:06 -05:00
selection: add start/end coordinate getters
Internally, selection coordinates are *unbounded* (that is, the row numbers may be larger than grid->num_rows) while a selection is ongoing. Only after it has been finalized are the coordinates bounded. This means it isn’t safe to use term->selection.coords.* directly.
This commit is contained in:
parent
b4f666118f
commit
6316a5eb0c
2 changed files with 27 additions and 0 deletions
24
selection.c
24
selection.c
|
|
@ -38,6 +38,29 @@ static const char *const mime_type_map[] = {
|
|||
[DATA_OFFER_MIME_TEXT_UTF8_STRING] = "UTF8_STRING",
|
||||
};
|
||||
|
||||
static inline struct coord
|
||||
bounded(const struct grid *grid, struct coord coord)
|
||||
{
|
||||
coord.row &= grid->num_rows - 1;
|
||||
return coord;
|
||||
}
|
||||
|
||||
struct coord
|
||||
selection_get_start(const struct terminal *term)
|
||||
{
|
||||
if (term->selection.coords.start.row < 0)
|
||||
return term->selection.coords.start;
|
||||
return bounded(term->grid, term->selection.coords.start);
|
||||
}
|
||||
|
||||
struct coord
|
||||
selection_get_end(const struct terminal *term)
|
||||
{
|
||||
if (term->selection.coords.end.row < 0)
|
||||
return term->selection.coords.end;
|
||||
return bounded(term->grid, term->selection.coords.end);
|
||||
}
|
||||
|
||||
bool
|
||||
selection_on_rows(const struct terminal *term, int row_start, int row_end)
|
||||
{
|
||||
|
|
@ -2461,3 +2484,4 @@ const struct zwp_primary_selection_device_v1_listener primary_selection_device_l
|
|||
.data_offer = &primary_data_offer,
|
||||
.selection = &primary_selection,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -79,3 +79,6 @@ void selection_find_word_boundary_left(
|
|||
struct terminal *term, struct coord *pos, bool spaces_only);
|
||||
void selection_find_word_boundary_right(
|
||||
struct terminal *term, struct coord *pos, bool spaces_only);
|
||||
|
||||
struct coord selection_get_start(const struct terminal *term);
|
||||
struct coord selection_get_end(const struct terminal *term);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue