mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-05-04 06:46:48 -04:00
selection: trim trailing spaces from block selections
The extract_*() family of functions can now optionally treat spaces as empty cells. Use this in selection_to_text() to trim trailing spaces from block selections. Closes #181
This commit is contained in:
parent
c9de30e2bc
commit
194cf1ce87
5 changed files with 13 additions and 5 deletions
|
|
@ -58,6 +58,8 @@
|
||||||
|
|
||||||
* Blinking text now uses the foreground color, but dimmed down in its
|
* Blinking text now uses the foreground color, but dimmed down in its
|
||||||
off state, instead of the background color.
|
off state, instead of the background color.
|
||||||
|
* Trailing spaces are trimmed when copying a block selection
|
||||||
|
(https://codeberg.org/dnkl/foot/issues/181).
|
||||||
|
|
||||||
|
|
||||||
### Deprecated
|
### Deprecated
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,11 @@ struct extraction_context {
|
||||||
const struct row *last_row;
|
const struct row *last_row;
|
||||||
const struct cell *last_cell;
|
const struct cell *last_cell;
|
||||||
enum selection_kind selection_kind;
|
enum selection_kind selection_kind;
|
||||||
|
bool trim_trailing_spaces;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct extraction_context *
|
struct extraction_context *
|
||||||
extract_begin(enum selection_kind kind)
|
extract_begin(enum selection_kind kind, bool trim_trailing_spaces)
|
||||||
{
|
{
|
||||||
struct extraction_context *ctx = malloc(sizeof(*ctx));
|
struct extraction_context *ctx = malloc(sizeof(*ctx));
|
||||||
if (unlikely(ctx == NULL)) {
|
if (unlikely(ctx == NULL)) {
|
||||||
|
|
@ -28,6 +29,7 @@ extract_begin(enum selection_kind kind)
|
||||||
|
|
||||||
*ctx = (struct extraction_context){
|
*ctx = (struct extraction_context){
|
||||||
.selection_kind = kind,
|
.selection_kind = kind,
|
||||||
|
.trim_trailing_spaces = trim_trailing_spaces,
|
||||||
};
|
};
|
||||||
return ctx;
|
return ctx;
|
||||||
}
|
}
|
||||||
|
|
@ -143,7 +145,7 @@ extract_one(const struct terminal *term, const struct row *row,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cell->wc == 0) {
|
if (cell->wc == 0 || (ctx->trim_trailing_spaces && cell->wc == L' ')) {
|
||||||
ctx->empty_count++;
|
ctx->empty_count++;
|
||||||
ctx->last_row = row;
|
ctx->last_row = row;
|
||||||
ctx->last_cell = cell;
|
ctx->last_cell = cell;
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,8 @@
|
||||||
|
|
||||||
struct extraction_context;
|
struct extraction_context;
|
||||||
|
|
||||||
struct extraction_context *extract_begin(enum selection_kind kind);
|
struct extraction_context *extract_begin(
|
||||||
|
enum selection_kind kind, bool trim_trailing_spaces);
|
||||||
|
|
||||||
bool extract_one(
|
bool extract_one(
|
||||||
const struct terminal *term, const struct row *row, const struct cell *cell,
|
const struct terminal *term, const struct row *row, const struct cell *cell,
|
||||||
|
|
|
||||||
|
|
@ -224,7 +224,10 @@ selection_to_text(const struct terminal *term)
|
||||||
if (term->selection.end.row == -1)
|
if (term->selection.end.row == -1)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
struct extraction_context *ctx = extract_begin(term->selection.kind);
|
const enum selection_kind kind = term->selection.kind;
|
||||||
|
const bool trim_trailing_spaces = kind == SELECTION_BLOCK;
|
||||||
|
|
||||||
|
struct extraction_context *ctx = extract_begin(kind, trim_trailing_spaces);
|
||||||
if (ctx == NULL)
|
if (ctx == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2651,7 +2651,7 @@ static bool
|
||||||
rows_to_text(const struct terminal *term, int start, int end,
|
rows_to_text(const struct terminal *term, int start, int end,
|
||||||
char **text, size_t *len)
|
char **text, size_t *len)
|
||||||
{
|
{
|
||||||
struct extraction_context *ctx = extract_begin(SELECTION_NONE);
|
struct extraction_context *ctx = extract_begin(SELECTION_NONE, false);
|
||||||
if (ctx == NULL)
|
if (ctx == NULL)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue