diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2022-02-02 21:02:56 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2022-02-03 16:58:25 +0000 |
| commit | 69e2bff8c8dbe0692651637539862cdb99aa9b30 (patch) | |
| tree | 08e5b05d3318bd8851d62f573c16a6309329d2e0 /extract.c | |
| parent | selection: don’t quote file URIs on the alt screen (diff) | |
extract: ensure line-based selections are terminated with a newline
Closes #869
Diffstat (limited to 'extract.c')
| -rw-r--r-- | extract.c | 21 |
1 files changed, 18 insertions, 3 deletions
@@ -86,9 +86,24 @@ extract_finish_wide(struct extraction_context *ctx, wchar_t **text, size_t *len) } else { xassert(ctx->idx > 0); xassert(ctx->idx <= ctx->size); - if (ctx->buf[ctx->idx - 1] == L'\n') - ctx->buf[ctx->idx - 1] = L'\0'; - else { + + switch (ctx->selection_kind) { + default: + if (ctx->buf[ctx->idx - 1] == L'\n') + ctx->buf[ctx->idx - 1] = L'\0'; + break; + + case SELECTION_LINE_WISE: + if (ctx->buf[ctx->idx - 1] != L'\n') { + if (!ensure_size(ctx, 1)) + goto err; + ctx->buf[ctx->idx++] = L'\n'; + } + break; + + } + + if (ctx->buf[ctx->idx - 1] != L'\0') { if (!ensure_size(ctx, 1)) goto err; ctx->buf[ctx->idx++] = L'\0'; |
