From f49699737c9b24e1af52719974cf3bc770539ef9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 17 May 2022 21:09:28 +0800 Subject: fix(terminal): do not trim whitespace that is actually in the terminal (#16423) --- src/nvim/terminal.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 2d3102707c..c8f70d4afd 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -1374,26 +1374,21 @@ static void fetch_row(Terminal *term, int row, int end_col) while (col < end_col) { VTermScreenCell cell; fetch_cell(term, row, col, &cell); - int cell_len = 0; if (cell.chars[0]) { + int cell_len = 0; for (int i = 0; cell.chars[i]; i++) { cell_len += utf_char2bytes((int)cell.chars[i], ptr + cell_len); } - } else { - *ptr = ' '; - cell_len = 1; - } - char c = *ptr; - ptr += cell_len; - if (c != ' ') { - // only increase the line length if the last character is not whitespace + ptr += cell_len; line_len = (size_t)(ptr - term->textbuf); + } else { + *ptr++ = ' '; } col += cell.width; } - // trim trailing whitespace - term->textbuf[line_len] = 0; + // end of line + term->textbuf[line_len] = NUL; } static bool fetch_cell(Terminal *term, int row, int col, VTermScreenCell *cell) -- cgit