diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e55316b..d8123eaa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,14 +52,15 @@ bindings. By default, they are bound to `ctrl+v ctrl+y` and `shift+insert` respectively, and lets you paste from the clipboard or primary selection into the search buffer. +* **trim-trailing-spaces-from-selection** option to `foot.init`. When + enabled, trailing spaces are trimmed from both regular and block + selections (https://codeberg.org/dnkl/foot/issues/181). ### Changed * Blinking text now uses the foreground color, but dimmed down in its off state, instead of the background color. -* Trailing spaces are trimmed when copying a block selection - (https://codeberg.org/dnkl/foot/issues/181). ### Deprecated diff --git a/config.c b/config.c index bb8324db..cff3a3f1 100644 --- a/config.c +++ b/config.c @@ -601,6 +601,9 @@ parse_section_main(const char *key, const char *value, struct config *conf, mbstowcs(conf->word_delimiters, value, chars + 1); } + else if (strcmp(key, "trim-trailing-spaces-from-selection") == 0) + conf->trim_trailing_spaces_from_selection = str_to_bool(value); + else if (strcmp(key, "scrollback") == 0) { LOG_WARN("deprecated: %s:%d: [default]: scrollback: use 'scrollback.lines' instead'", path, lineno); @@ -2081,6 +2084,7 @@ config_load(struct config *conf, const char *conf_path, .server_socket_path = get_server_socket_path(), .presentation_timings = false, .hold_at_exit = false, + .trim_trailing_spaces_from_selection = false, .tweak = { .fcft_filter = FCFT_SCALING_FILTER_LANCZOS3, diff --git a/config.h b/config.h index 48961790..dc9061aa 100644 --- a/config.h +++ b/config.h @@ -168,6 +168,7 @@ struct config { char *server_socket_path; bool presentation_timings; bool hold_at_exit; + bool trim_trailing_spaces_from_selection; struct { enum fcft_scaling_filter fcft_filter; diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index 39d874e0..5c0fdd57 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -128,6 +128,10 @@ in this order: text. Note that whitespace characters are _always_ word delimiters, regardless of this setting. Default: _,│`|:"'()[]{}<>_ +*trim-trailing-spaces-from-selection* + Boolean. If enabled, trailing spaces are trimmed from selections + (both regular and block selections). Default: _no_. + # SECTION: scrollback diff --git a/foot.ini b/foot.ini index 8f8d4493..338760a5 100644 --- a/foot.ini +++ b/foot.ini @@ -14,6 +14,7 @@ # workers= # bell=none # word-delimiters=,│`|:"'()[]{}<> +# trim-trailing-spaces-from-selection=no [scrollback] # lines=1000 diff --git a/selection.c b/selection.c index 558689e6..ff25e542 100644 --- a/selection.c +++ b/selection.c @@ -224,10 +224,9 @@ selection_to_text(const struct terminal *term) if (term->selection.end.row == -1) return NULL; - const enum selection_kind kind = term->selection.kind; - const bool trim_trailing_spaces = kind == SELECTION_BLOCK; + struct extraction_context *ctx = extract_begin( + term->selection.kind, term->conf->trim_trailing_spaces_from_selection); - struct extraction_context *ctx = extract_begin(kind, trim_trailing_spaces); if (ctx == NULL) return NULL;