[vim/vim] Virtual text displays wrongly with warp & linebreak (Issue #12998)

13 views
Skip to first unread message

Adam Tao

unread,
Sep 1, 2023, 3:33:25 AM9/1/23
to vim/vim, Subscribed

Steps to reproduce

  1. Save the following script as a file (e.g., repro.vim):
set wrap
set linebreak
set breakindent
set breakindentopt+=shift:4

call append(0, ["a b", "c d"])
normal! 2gg

call prop_type_add( 'Normal' , {'highlight': 'Normal'}  )
call prop_add( 1 ,  0 ,  {'type': 'Normal', 'text': '123', 'text_align': 'above'}  )
  1. Run vim --clean
  2. :source repro.vim

Expected behaviour

Vim should show the content like:

123
a b
c d

Version of Vim

9.0.1833

Environment

OS: Fedora 38
Terminal: Windows Terminal (using ssh to connect to the Fedora)
Value of $TERM: xterm-256color
Shell: zsh 5.9

Logs and stack traces

No response


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/12998@github.com>

Adam Tao

unread,
Sep 1, 2023, 3:35:19 AM9/1/23
to vim/vim, Subscribed

The actual content after source looks like:

123
a    b
c d

image


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/12998/1702305781@github.com>

Adam Tao

unread,
Sep 1, 2023, 3:36:08 AM9/1/23
to vim/vim, Subscribed

After some bisect, it looks like that b557f48 ("patch 9.0.1783: Display issues with virt text smoothscroll and showbreak") causes the issue


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/12998/1702306943@github.com>

zeertzjq

unread,
Sep 1, 2023, 4:14:56 AM9/1/23
to vim/vim, Subscribed

It seems that the cursor position is also incorrect without 'linebreak'.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/12998/1702353040@github.com>

zeertzjq

unread,
Sep 1, 2023, 4:15:47 AM9/1/23
to vim/vim, Subscribed

This fixes the redrawing problem, but not cursor position:

diff --git a/src/charset.c b/src/charset.c
index 3495a0ee1..f218c42b1 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -1126,8 +1126,11 @@ win_lbr_chartabsize(
 #endif
 
 #if defined(FEAT_PROP_POPUP)
-    cts->cts_cur_text_width = 0;
-    cts->cts_first_char = 0;
+    if (cts->cts_has_prop_with_text)
+    {
+	cts->cts_cur_text_width = 0;
+	cts->cts_first_char = 0;
+    }
 #endif
 
 #if defined(FEAT_LINEBREAK) || defined(FEAT_PROP_POPUP)
@@ -1264,7 +1267,7 @@ win_lbr_chartabsize(
 	int	width2 = wp->w_width - col_off_prev + win_col_off2(wp);
 	colnr_T	wcol = vcol + col_off_prev;
 #ifdef FEAT_PROP_POPUP
-	wcol -= wp->w_virtcol_first_char;
+	wcol -= cts->cts_first_char;
 #endif
 	colnr_T	max_head_vcol = cts->cts_max_head_vcol;
 	int	added = 0;
diff --git a/src/drawline.c b/src/drawline.c
index 63bc96c4d..3bac16155 100644
--- a/src/drawline.c
+++ b/src/drawline.c
@@ -2879,8 +2879,14 @@ win_line(
 		    char_u  *p = ptr - (mb_off + 1);
 		    chartabsize_T cts;
 
+		    init_chartabsize_arg(&cts, wp, lnum, 0, line, line);
+		    (void)win_lbr_chartabsize(&cts, NULL);
+		    colnr_T cts_first_char = cts.cts_first_char;
+		    clear_chartabsize_arg(&cts);
+
 		    init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
 # ifdef FEAT_PROP_POPUP
+		    cts.cts_first_char = cts_first_char;
 		    // do not want virtual text counted here
 		    cts.cts_has_prop_with_text = FALSE;
 # endif


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/12998/1702353996@github.com>

zeertzjq

unread,
Sep 1, 2023, 4:27:10 AM9/1/23
to vim/vim, Subscribed

And this fixes the cursor position without 'linebreak':

diff --git a/src/charset.c b/src/charset.c
index 3495a0ee1..27539dd27 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -1218,8 +1218,9 @@ win_lbr_chartabsize(
 		    cts->cts_cur_text_width += cells;
 		    if (tp->tp_flags & TP_FLAG_ALIGN_ABOVE)
 			cts->cts_first_char += cells;
+		    else
+			size += cells;
 		    cts->cts_start_incl = tp->tp_flags & TP_FLAG_START_INCL;
-		    size += cells;
 		    if (*s == TAB)
 		    {
 			// tab size changes because of the inserted text
@@ -1385,6 +1386,9 @@ win_lbr_chartabsize(
 	}
     }
 
+#  ifdef FEAT_PROP_POPUP
+    size += cts->cts_first_char;
+#  endif
     return size;
 # endif
 #endif


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/12998/1702367835@github.com>

Adam Tao

unread,
Sep 1, 2023, 4:48:23 AM9/1/23
to vim/vim, Subscribed

@zeertzjq Thanks for your quick reply! I have tested in my own env and it works! And the patch fixes the issue I mentioned in #12999 too.

Is there any plan to open a PR for the fix?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/12998/1702396004@github.com>

zeertzjq

unread,
Sep 1, 2023, 4:49:36 AM9/1/23
to vim/vim, Subscribed

I'll create a PR soon, after writing tests.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/12998/1702397678@github.com>

Adam Tao

unread,
Sep 1, 2023, 4:57:02 AM9/1/23
to vim/vim, Subscribed

Emm, only the script in #12999 can't reproduce but the issue is still existing. Maybe I shall write a new script to reproduce the issue in #12999 .


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/12998/1702407428@github.com>

Christian Brabandt

unread,
Sep 1, 2023, 12:52:47 PM9/1/23
to vim/vim, Subscribed

should be fixed by ce53e3e


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/12998/1703043326@github.com>

Christian Brabandt

unread,
Sep 1, 2023, 12:52:53 PM9/1/23
to vim/vim, Subscribed

Closed #12998 as completed.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issue/12998/issue_event/10259274305@github.com>

Reply all
Reply to author
Forward
0 new messages