-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix CUI setcellwidths
characters draw behavior to same GUI behavior.
#14540
Fix CUI setcellwidths
characters draw behavior to same GUI behavior.
#14540
Conversation
I think this will cause performance problems. For example, if there are a lot of double-width characters on the screen, this will cause a lot of cursor positioning escape sequences even if |
@zeertzjq I have changed the processing order so that it checks if the character is specified by setcellwidths before the existing process. Would this solve the problem? diff from master branch: diff --git a/src/mbyte.c b/src/mbyte.c
index d6fb7ecc7..726843315 100644
--- a/src/mbyte.c
+++ b/src/mbyte.c
@@ -140,6 +140,7 @@ static int dbcs_head_off(char_u *base, char_u *p);
#ifdef FEAT_EVAL
static int cw_value(int c);
#endif
+int get_cellwidth(int c);
/*
* Lookup table to quickly get the length in bytes of a UTF-8 character from
@@ -5542,6 +5543,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)
+{
+#ifdef FEAT_EVAL
+ return cw_value(c);
+#else
+ return 0;
+#endif
+}
+
#if defined(FEAT_EVAL) || defined(PROTO)
/*
diff --git a/src/proto/mbyte.pro b/src/proto/mbyte.pro
index 7883b3b4c..c57c94c8a 100644
--- a/src/proto/mbyte.pro
+++ b/src/proto/mbyte.pro
@@ -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);
diff --git a/src/screen.c b/src/screen.c
index 71ddbcaab..8f0c8f058 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -1981,6 +1981,29 @@ screen_char(unsigned off, int row, int col)
{
char_u buf[MB_MAXBYTES + 1];
+ 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 it is not specified in `setcellwidths`
+ // or if a width of 1 is encountered in `setcellwidths`,
+ // do the same as the original.
+
if (utf_ambiguous_width(ScreenLinesUC[off]))
{
if (*p_ambw == 'd'
@@ -2000,6 +2023,7 @@ screen_char(unsigned off, int row, int col)
}
else if (utf_char2cells(ScreenLinesUC[off]) > 1)
++screen_cur_col;
+ }
// Convert the UTF-8 character to bytes and write it.
buf[utfc_char2bytes(off, buf)] = NUL; |
Yes, I think that makes sense, but there is no need to say "same as original" in the comment, and the last |
Thank you. I will fix it! |
f385408
to
cd945ef
Compare
I fixed and rebased commit. |
thanks, can you please add a test for that? |
This can now be partly tested by enabling the skipped part of the test in a59e031 (removing the |
cd945ef
to
1187d04
Compare
I added tests and delete |
thanks! |
Unfortunately, there are still some CI errors |
src/mbyte.c
Outdated
@@ -140,6 +140,7 @@ static int dbcs_head_off(char_u *base, char_u *p); | |||
#ifdef FEAT_EVAL | |||
static int cw_value(int c); | |||
#endif | |||
int get_cellwidth(int c); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not needed because it's a non-static function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you.
Fixed in commit c69bff0.
Sorry, I had not set CFLAGS when doing the local build. Can the following three errors, which also appear in some other CIs, be ignored for this Pull Request?
For example, similar issues have occurred in other CIs, such as: https://github.com/vim/vim/actions/runs/8711945284/ |
https://github.com/vim/vim/actions/runs/8702081110/job/23897551049 only appears on this PR. |
Added `UNUSED` to the parameter `c` of `get_cellwidth` because it is not used when the build flag `FEAT_EVAL` is not defined.
I Fixed build error in commit 87feae6. |
I apologize, I sent the wrong links. Here are the correct three:
|
Yes, those are unrelated to this PR. |
Understood, thank you! |
thanks. Looks good now |
Problem: Cursor wrong after using setcellwidth() in terminal (mikoto2000) Solution: output additional spaces, so the behaviour matches the GUI (mikoto2000) fixes: vim/vim#14539 closes: vim/vim#14540 Fix CUI `setcellwidths` characters draw behavior to same GUI behavior. vim/vim@e20fa59 This is already fixed and tested in Nvim in neovim#28322. Co-authored-by: mikoto2000 <mikoto2000@gmail.com>
…al (#28391) Problem: Cursor wrong after using setcellwidth() in terminal (mikoto2000) Solution: output additional spaces, so the behaviour matches the GUI (mikoto2000) fixes: vim/vim#14539 closes: vim/vim#14540 Fix CUI `setcellwidths` characters draw behavior to same GUI behavior. vim/vim@e20fa59 This is already fixed and tested in Nvim in #28322. Co-authored-by: mikoto2000 <mikoto2000@gmail.com>
…al (neovim#28391) Problem: Cursor wrong after using setcellwidth() in terminal (mikoto2000) Solution: output additional spaces, so the behaviour matches the GUI (mikoto2000) fixes: vim/vim#14539 closes: vim/vim#14540 Fix CUI `setcellwidths` characters draw behavior to same GUI behavior. vim/vim@e20fa59 This is already fixed and tested in Nvim in neovim#28322. Co-authored-by: mikoto2000 <mikoto2000@gmail.com>
Fixed #14539 issue.