]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0344: Cursor wrong after using setcellwidth() in terminal v9.1.0344
authormikoto2000 <mikoto2000@gmail.com>
Wed, 17 Apr 2024 20:06:54 +0000 (22:06 +0200)
committerChristian Brabandt <cb@256bit.org>
Wed, 17 Apr 2024 20:06:54 +0000 (22:06 +0200)
Problem:  Cursor wrong after using setcellwidth() in terminal
          (mikoto2000)
Solution: output additional spaces, so the behaviour matches the GUI
          (mikoto2000)

fixes: #14539
closes: #14540

Signed-off-by: mikoto2000 <mikoto2000@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
Fix CUI `setcellwidths` characters draw behavior to same GUI behavior.

src/mbyte.c
src/proto/mbyte.pro
src/screen.c
src/testdir/dumps/Test_setcellwidths_with_non_ambiwidth_character_dump_1.dump [new file with mode: 0644]
src/testdir/dumps/Test_setcellwidths_with_non_ambiwidth_character_dump_2.dump [new file with mode: 0644]
src/testdir/test_utf8.vim
src/version.c

index 406d1093ffac5a0410070d69bb39358a24b8f406..07446ca56162abbc11ee19377316735ee82d4bba 100644 (file)
@@ -5542,6 +5542,20 @@ string_convert_ext(
     return retval;
 }
 
+/*
+ * Return 1 or 2 when "c" is in the cellwidth table.
+ * Return 0 if not.
+ */
+    int
+get_cellwidth(int c UNUSED)
+{
+#ifdef FEAT_EVAL
+    return cw_value(c);
+#else
+    return 0;
+#endif
+}
+
 #if defined(FEAT_EVAL) || defined(PROTO)
 
 /*
index 7883b3b4c7331093ea3b3618fed492151eef9794..c57c94c8aedb432dd1c830d7113408df3df7a292 100644 (file)
@@ -85,6 +85,7 @@ int convert_input(char_u *ptr, int len, int maxlen);
 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);
index 71ddbcaab220c0b77c38fbdd87af829f11596dba..a8b4559b118329771d3ed986ba0821a18067155d 100644 (file)
@@ -1981,7 +1981,24 @@ screen_char(unsigned off, int row, int col)
     {
        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
diff --git a/src/testdir/dumps/Test_setcellwidths_with_non_ambiwidth_character_dump_1.dump b/src/testdir/dumps/Test_setcellwidths_with_non_ambiwidth_character_dump_1.dump
new file mode 100644 (file)
index 0000000..73f4418
--- /dev/null
@@ -0,0 +1,6 @@
+>➜+0&#ffffff0@49
+@10| @39
+|➜@49
+@10| @39
+|~+0#4040ff13&| @48
+| +0#0000000&@31|1|,|1| @10|A|l@1| 
diff --git a/src/testdir/dumps/Test_setcellwidths_with_non_ambiwidth_character_dump_2.dump b/src/testdir/dumps/Test_setcellwidths_with_non_ambiwidth_character_dump_2.dump
new file mode 100644 (file)
index 0000000..2b575f6
--- /dev/null
@@ -0,0 +1,6 @@
+>➜+0&#ffffff0| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| 
+|➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| 
+|➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| @30
+|➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| |➜| 
+|@+0#4040ff13&@2| @46
+| +0#0000000&@31|1|,|1| @10|T|o|p| 
index df0abd354c80f613ba6731f43fa0044f9589415d..3fd83cf79f15d44a944ea1792d08284e0b97059b 100644 (file)
@@ -300,6 +300,28 @@ func Test_setcellwidths_dump()
   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()
@@ -321,7 +343,6 @@ 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', {})
@@ -329,7 +350,6 @@ func Test_zz_ambiwidth_hl_dump()
   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
index 3c1eae66a5b31a4a1942199a52f543d4fdb2f4d9..d4f82ba586262429fb5b2c5247ba10df6974a319 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    344,
 /**/
     343,
 /**/