diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-04-14 09:29:38 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-14 09:29:38 +0800 |
commit | 4c31a1b807f1c38203661e35059305d63fd0e9f7 (patch) | |
tree | 617408cd5e72389e1a4a0aff52442c4bae0872db /src | |
parent | a92822835521574710a830a7de0e692bf7517fb8 (diff) | |
download | rneovim-4c31a1b807f1c38203661e35059305d63fd0e9f7.tar.gz rneovim-4c31a1b807f1c38203661e35059305d63fd0e9f7.tar.bz2 rneovim-4c31a1b807f1c38203661e35059305d63fd0e9f7.zip |
fix(tui): make setcellwidths() work for non-ambiwidth chars (#28322)
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/tui/tui.c | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index 29354a4f07..f9bdf6843a 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -963,17 +963,17 @@ static void print_spaces(TUIData *tui, int width) } } -/// Move cursor to the position given by `row` and `col` and print the character in `cell`. -/// This allows the grid and the host terminal to assume different widths of ambiguous-width chars. +/// Move cursor to the position given by `row` and `col` and print the char in `cell`. +/// Allows grid and host terminal to assume different widths of ambiguous-width chars. /// -/// @param is_doublewidth whether the character is double-width on the grid. -/// If true and the character is ambiguous-width, clear two cells. +/// @param is_doublewidth whether the char is double-width on the grid. +/// If true and the char is ambiguous-width, clear two cells. static void print_cell_at_pos(TUIData *tui, int row, int col, UCell *cell, bool is_doublewidth) { UGrid *grid = &tui->grid; if (grid->row == -1 && cell->data == NUL) { - // If cursor needs to repositioned and there is nothing to print, don't move cursor. + // If cursor needs repositioning and there is nothing to print, don't move cursor. return; } @@ -981,10 +981,14 @@ static void print_cell_at_pos(TUIData *tui, int row, int col, UCell *cell, bool char buf[MAX_SCHAR_SIZE]; schar_get(buf, cell->data); - bool is_ambiwidth = utf_ambiguous_width(utf_ptr2char(buf)); - if (is_ambiwidth && is_doublewidth) { + int c = utf_ptr2char(buf); + bool is_ambiwidth = utf_ambiguous_width(c); + if (is_doublewidth && (is_ambiwidth || utf_char2cells(c) == 1)) { + // If the server used setcellwidths() to treat a single-width char as double-width, + // it needs to be treated like an ambiguous-width char. + is_ambiwidth = true; // Clear the two screen cells. - // If the character is single-width in the host terminal it won't change the second cell. + // If the char is single-width in host terminal it won't change the second cell. update_attrs(tui, cell->attr); print_spaces(tui, 2); cursor_goto(tui, row, col); @@ -993,7 +997,7 @@ static void print_cell_at_pos(TUIData *tui, int row, int col, UCell *cell, bool print_cell(tui, buf, cell->attr); if (is_ambiwidth) { - // Force repositioning cursor after printing an ambiguous-width character. + // Force repositioning cursor after printing an ambiguous-width char. grid->row = -1; } } |