int convert_input_safe(char_u *ptr, int len, int maxlen, char_u **restp, int *restlenp);
char_u *string_convert(vimconv_T *vcp, char_u *ptr, int *lenp);
char_u *string_convert_ext(vimconv_T *vcp, char_u *ptr, int *lenp, int *unconvlenp);
+int get_cellwidth(int c);
void f_setcellwidths(typval_T *argvars, typval_T *rettv);
void f_getcellwidths(typval_T *argvars, typval_T *rettv);
void f_charclass(typval_T *argvars, typval_T *rettv);
{
char_u buf[MB_MAXBYTES + 1];
- if (utf_ambiguous_width(ScreenLinesUC[off]))
+ if (get_cellwidth(ScreenLinesUC[off]) > 1)
+ {
+ // If the width is set to 2 with `setcellwidths`
+
+#ifdef FEAT_GUI
+ if (!gui.in_use)
+ {
+#endif
+ // Clear the two screen cells. If the character is actually
+ // single width it won't change the second cell.
+ out_str((char_u *)" ");
+ term_windgoto(row, col);
+ screen_cur_col = 9999;
+#ifdef FEAT_GUI
+ }
+#endif
+ }
+ else if (utf_ambiguous_width(ScreenLinesUC[off]))
{
if (*p_ambw == 'd'
#ifdef FEAT_GUI
call StopVimInTerminal(buf)
endfunc
+" When `setcellwidth` is used on characters that are not targets of `ambiwidth`.
+func Test_setcellwidths_with_non_ambiwidth_character_dump()
+ CheckRunVimInTerminal
+
+ let lines =<< trim END
+ call setline(1, [repeat("\u279c", 60), repeat("\u279c", 60)])
+ set ambiwidth=single
+ END
+ call writefile(lines, 'XCellwidthsWithNonAmbiwidthCharacter', 'D')
+ let buf = RunVimInTerminal('-S XCellwidthsWithNonAmbiwidthCharacter', {'rows': 6, 'cols': 50})
+ call term_sendkeys(buf, ":call setcellwidths([[0x279c, 0x279c, 1]])\<CR>")
+ call term_sendkeys(buf, ":echo\<CR>")
+ call VerifyScreenDump(buf, 'Test_setcellwidths_with_non_ambiwidth_character_dump_1', {})
+
+ call term_sendkeys(buf, ":call setcellwidths([[0x279c, 0x279c, 2]])\<CR>")
+ call term_sendkeys(buf, ":echo\<CR>")
+ call VerifyScreenDump(buf, 'Test_setcellwidths_with_non_ambiwidth_character_dump_2', {})
+
+ call StopVimInTerminal(buf)
+endfunc
+
+
" For some reason this test causes Test_customlist_completion() to fail on CI,
" so run it as the last test.
func Test_zz_ambiwidth_hl_dump()
call term_sendkeys(buf, ":echo\<CR>")
call VerifyScreenDump(buf, 'Test_ambiwidth_hl_dump_1', {})
- if 0 " Enable after #14539 is fixed
call term_sendkeys(buf, ":call setcellwidths([[0x2103, 0x2103, 2]])\<CR>")
call term_sendkeys(buf, ":echo\<CR>")
call VerifyScreenDump(buf, 'Test_ambiwidth_hl_dump_2', {})
call term_sendkeys(buf, ":call setcellwidths([[0x2103, 0x2103, 1]])\<CR>")
call term_sendkeys(buf, ":echo\<CR>")
call VerifyScreenDump(buf, 'Test_ambiwidth_hl_dump_1', {})
- endif
call StopVimInTerminal(buf)
endfunc