mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-04-05 07:15:30 -04:00
selection: calculate required length for clipboard text
This commit is contained in:
parent
c1c6646b98
commit
6edc3845bd
1 changed files with 12 additions and 3 deletions
15
selection.c
15
selection.c
|
|
@ -34,8 +34,17 @@ extract_selection(const struct terminal *term)
|
||||||
|
|
||||||
assert(start->row <= end->row);
|
assert(start->row <= end->row);
|
||||||
|
|
||||||
/* TODO: calculate length required */
|
size_t max_cells = 0;
|
||||||
char buf[4096];
|
if (start->row == end->row) {
|
||||||
|
assert(start->col <= end->col);
|
||||||
|
max_cells = end->col - start->col + 1;
|
||||||
|
} else {
|
||||||
|
max_cells = term->cols - start->col;
|
||||||
|
max_cells += term->cols * (end->row - start->row - 1);
|
||||||
|
max_cells += end->col + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *buf = malloc(max_cells * 4 + 1);
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
|
|
||||||
int start_col = start->col;
|
int start_col = start->col;
|
||||||
|
|
@ -75,7 +84,7 @@ extract_selection(const struct terminal *term)
|
||||||
}
|
}
|
||||||
|
|
||||||
buf[idx] = '\0';
|
buf[idx] = '\0';
|
||||||
return strdup(buf);
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue