]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1796: Wrong cursor position with wrapped "after" virtual text and 'sbr' v9.1.1796
authorzeertzjq <zeertzjq@outlook.com>
Fri, 26 Sep 2025 17:00:10 +0000 (17:00 +0000)
committerChristian Brabandt <cb@256bit.org>
Fri, 26 Sep 2025 17:00:10 +0000 (17:00 +0000)
Problem:  Wrong cursor position with wrapped "after" virtual text and
          'showbreak' (Ben Jackson)
Solution: Count size of 'showbreak' in wrapped "after" virtual text in
          line size (zeertzjq).

fixes: #18398
closes: #18400

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
17 files changed:
src/charset.c
src/drawline.c
src/proto/drawline.pro
src/testdir/dumps/Test_text_after_wrap_showbreak_01.dump [new file with mode: 0644]
src/testdir/dumps/Test_text_after_wrap_showbreak_02.dump [new file with mode: 0644]
src/testdir/dumps/Test_text_after_wrap_showbreak_03.dump [new file with mode: 0644]
src/testdir/dumps/Test_text_after_wrap_showbreak_04.dump [new file with mode: 0644]
src/testdir/dumps/Test_text_after_wrap_showbreak_05.dump [new file with mode: 0644]
src/testdir/dumps/Test_text_after_wrap_showbreak_06.dump [new file with mode: 0644]
src/testdir/dumps/Test_text_after_wrap_showbreak_07.dump [new file with mode: 0644]
src/testdir/dumps/Test_text_after_wrap_showbreak_08.dump [new file with mode: 0644]
src/testdir/dumps/Test_text_after_wrap_showbreak_09.dump [new file with mode: 0644]
src/testdir/dumps/Test_text_after_wrap_showbreak_10.dump [new file with mode: 0644]
src/testdir/dumps/Test_text_after_wrap_showbreak_11.dump [new file with mode: 0644]
src/testdir/dumps/Test_text_after_wrap_showbreak_12.dump [new file with mode: 0644]
src/testdir/test_textprop.vim
src/version.c

index 9c68d4af75920a3c7e6443df77d8accf9507ec39..e595cd937eaf78bdc042006a58b8029792260d22 100644 (file)
@@ -918,8 +918,9 @@ win_linetabsize_cts(chartabsize_T *cts, colnr_T len)
     // check for a virtual text at the end of a line or on an empty line
     if (len == MAXCOL && cts->cts_has_prop_with_text && *cts->cts_ptr == NUL)
     {
-       (void)win_lbr_chartabsize(cts, NULL);
-       vcol += cts->cts_cur_text_width;
+       int head = 0;
+       (void)win_lbr_chartabsize(cts, &head);
+       vcol += cts->cts_cur_text_width + head;
        // when properties are above or below the empty line must also be
        // counted
        if (cts->cts_ptr == cts->cts_line && cts->cts_prop_lines > 0)
@@ -1325,7 +1326,8 @@ win_lbr_chartabsize(
                             (vcol + size) % (wp->w_width - col_off) + col_off,
                                              &n_extra, &p, NULL, NULL, FALSE);
 #  ifdef FEAT_LINEBREAK
-                       no_sbr = TRUE;  // don't use 'showbreak' now
+                       if (text_prop_no_showbreak(tp))
+                           no_sbr = TRUE;  // don't use 'showbreak' now
 #  endif
                    }
                    else
index 497ba5b85c41a6f5649d4e15db47cd18097c92d5..978ffee0b05ec0182658ac4b02446628501e836d 100644 (file)
@@ -829,6 +829,23 @@ text_prop_position(
        return cells;
     return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
 }
+
+# if defined(FEAT_LINEBREAK) || defined(PROTO)
+/*
+ * no 'showbreak' before "below" text property
+ * or after "above" or "right" text property
+ */
+    int
+text_prop_no_showbreak(textprop_T *tp)
+{
+    int            right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
+    int            above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
+    int            below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
+    int            wrap = tp->tp_col < MAXCOL || (tp->tp_flags & TP_FLAG_WRAP);
+
+    return (right || above || below || !wrap);
+}
+# endif
 #endif
 
 /*
@@ -2258,10 +2275,8 @@ win_line(
                                // don't combine char attr after EOL
                                text_prop_flags &= ~PT_FLAG_COMBINE;
 # ifdef FEAT_LINEBREAK
-                           if (above || below || right || !wrap)
+                           if (text_prop_no_showbreak(tp))
                            {
-                               // no 'showbreak' before "below" text property
-                               // or after "above" or "right" text property
                                wlv.need_showbreak = FALSE;
                                wlv.dont_use_showbreak = TRUE;
                            }
index 141ca1b9c21dbef9883ff2b5336059d7e9870935..abda9cf74ae279ee4ccd902cac8196962e7aa7f7 100644 (file)
@@ -1,4 +1,5 @@
 /* drawline.c */
 int text_prop_position(win_T *wp, textprop_T *tp, int vcol, int scr_col, int *n_extra, char_u **p_extra, int *n_attr, int *n_attr_skip, int do_skip);
+int text_prop_no_showbreak(textprop_T *tp);
 int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, int number_only, spellvars_T *spv);
 /* vim: set ft=c : */
diff --git a/src/testdir/dumps/Test_text_after_wrap_showbreak_01.dump b/src/testdir/dumps/Test_text_after_wrap_showbreak_01.dump
new file mode 100644 (file)
index 0000000..ae2c456
--- /dev/null
@@ -0,0 +1,8 @@
+> +8&#ffffff0@7|"| |1|2|3|4|5|6|7|8|9|0
+|>+8#4040ff13&| |a+8#0000001#a8a8a8255@3|8|9|0| |1|2|3| |4|5|6| |7|8
+|>+8#4040ff13#ffffff0| |9+8#0000001#a8a8a8255| +8#0000000#ffffff0@16
+|f+0&&|o@1| @16
+|b|a|r| @16
+|~+0#4040ff13&| @18
+|~| @18
+| +0#0000000&@9|1|,|1| @2|A|l@1| 
diff --git a/src/testdir/dumps/Test_text_after_wrap_showbreak_02.dump b/src/testdir/dumps/Test_text_after_wrap_showbreak_02.dump
new file mode 100644 (file)
index 0000000..72c044a
--- /dev/null
@@ -0,0 +1,8 @@
+| +0&#ffffff0@7|"| |1|2|3|4|5|6|7|8|9|0
+|>+0#4040ff13&| |a+0#0000001#a8a8a8255@3|8|9|0| |1|2|3| |4|5|6| |7|8
+|>+0#4040ff13#ffffff0| |9+0#0000001#a8a8a8255| +0#0000000#ffffff0@16
+>f+8&&|o@1| @16
+|b+0&&|a|r| @16
+|~+0#4040ff13&| @18
+|~| @18
+| +0#0000000&@9|2|,|1| @2|A|l@1| 
diff --git a/src/testdir/dumps/Test_text_after_wrap_showbreak_03.dump b/src/testdir/dumps/Test_text_after_wrap_showbreak_03.dump
new file mode 100644 (file)
index 0000000..39d6557
--- /dev/null
@@ -0,0 +1,8 @@
+| +0&#ffffff0@7|"| |1|2|3|4|5|6|7|8|9|0
+|>+0#4040ff13&| |a+0#0000001#a8a8a8255@3|8|9|0| |1|2|3| |4|5|6| |7|8
+|>+0#4040ff13#ffffff0| |9+0#0000001#a8a8a8255| +0#0000000#ffffff0@16
+|f|o@1| @16
+>b+8&&|a|r| @16
+|~+0#4040ff13&| @18
+|~| @18
+| +0#0000000&@9|3|,|1| @2|A|l@1| 
diff --git a/src/testdir/dumps/Test_text_after_wrap_showbreak_04.dump b/src/testdir/dumps/Test_text_after_wrap_showbreak_04.dump
new file mode 100644 (file)
index 0000000..c19159d
--- /dev/null
@@ -0,0 +1,8 @@
+> +8&#ffffff0@7|"| |1|2|3|4|5|6|7|8|9|a+8#0000001#a8a8a8255
+|>+8#4040ff13#ffffff0| |a+8#0000001#a8a8a8255@2|8|9|0| |1|2|3| |4|5|6| |7|8|9
+|f+0#0000000#ffffff0|o@1| @16
+|b|a|r| @16
+|~+0#4040ff13&| @18
+|~| @18
+|~| @18
+| +0#0000000&@9|1|,|1| @2|A|l@1| 
diff --git a/src/testdir/dumps/Test_text_after_wrap_showbreak_05.dump b/src/testdir/dumps/Test_text_after_wrap_showbreak_05.dump
new file mode 100644 (file)
index 0000000..56ddaf1
--- /dev/null
@@ -0,0 +1,8 @@
+| +0&#ffffff0@7|"| |1|2|3|4|5|6|7|8|9|a+0#0000001#a8a8a8255
+|>+0#4040ff13#ffffff0| |a+0#0000001#a8a8a8255@2|8|9|0| |1|2|3| |4|5|6| |7|8|9
+>f+8#0000000#ffffff0|o@1| @16
+|b+0&&|a|r| @16
+|~+0#4040ff13&| @18
+|~| @18
+|~| @18
+| +0#0000000&@9|2|,|1| @2|A|l@1| 
diff --git a/src/testdir/dumps/Test_text_after_wrap_showbreak_06.dump b/src/testdir/dumps/Test_text_after_wrap_showbreak_06.dump
new file mode 100644 (file)
index 0000000..ff3c992
--- /dev/null
@@ -0,0 +1,8 @@
+| +0&#ffffff0@7|"| |1|2|3|4|5|6|7|8|9|a+0#0000001#a8a8a8255
+|>+0#4040ff13#ffffff0| |a+0#0000001#a8a8a8255@2|8|9|0| |1|2|3| |4|5|6| |7|8|9
+|f+0#0000000#ffffff0|o@1| @16
+>b+8&&|a|r| @16
+|~+0#4040ff13&| @18
+|~| @18
+|~| @18
+| +0#0000000&@9|3|,|1| @2|A|l@1| 
diff --git a/src/testdir/dumps/Test_text_after_wrap_showbreak_07.dump b/src/testdir/dumps/Test_text_after_wrap_showbreak_07.dump
new file mode 100644 (file)
index 0000000..bf75a92
--- /dev/null
@@ -0,0 +1,8 @@
+> +8&#ffffff0@7|"| |1|2|3|4|5|6|7|8|9|$+8#4040ff13&
+|>| |a+8#0000001#a8a8a8255@3|8|9|0| |1|2|3| |4|5|6| |7|8
+|>+8#4040ff13#ffffff0| |9+8#0000001#a8a8a8255| +8#0000000#ffffff0@16
+|f+0&&|o@1|$+0#4040ff13&| +0#0000000&@15
+|b|a|r|$+0#4040ff13&| +0#0000000&@15
+|~+0#4040ff13&| @18
+|~| @18
+| +0#0000000&@9|1|,|1| @2|A|l@1| 
diff --git a/src/testdir/dumps/Test_text_after_wrap_showbreak_08.dump b/src/testdir/dumps/Test_text_after_wrap_showbreak_08.dump
new file mode 100644 (file)
index 0000000..1a83d3e
--- /dev/null
@@ -0,0 +1,8 @@
+| +0&#ffffff0@7|"| |1|2|3|4|5|6|7|8|9|$+0#4040ff13&
+|>| |a+0#0000001#a8a8a8255@3|8|9|0| |1|2|3| |4|5|6| |7|8
+|>+0#4040ff13#ffffff0| |9+0#0000001#a8a8a8255| +0#0000000#ffffff0@16
+>f+8&&|o@1|$+8#4040ff13&| +8#0000000&@15
+|b+0&&|a|r|$+0#4040ff13&| +0#0000000&@15
+|~+0#4040ff13&| @18
+|~| @18
+| +0#0000000&@9|2|,|1| @2|A|l@1| 
diff --git a/src/testdir/dumps/Test_text_after_wrap_showbreak_09.dump b/src/testdir/dumps/Test_text_after_wrap_showbreak_09.dump
new file mode 100644 (file)
index 0000000..9392da8
--- /dev/null
@@ -0,0 +1,8 @@
+| +0&#ffffff0@7|"| |1|2|3|4|5|6|7|8|9|$+0#4040ff13&
+|>| |a+0#0000001#a8a8a8255@3|8|9|0| |1|2|3| |4|5|6| |7|8
+|>+0#4040ff13#ffffff0| |9+0#0000001#a8a8a8255| +0#0000000#ffffff0@16
+|f|o@1|$+0#4040ff13&| +0#0000000&@15
+>b+8&&|a|r|$+8#4040ff13&| +8#0000000&@15
+|~+0#4040ff13&| @18
+|~| @18
+| +0#0000000&@9|3|,|1| @2|A|l@1| 
diff --git a/src/testdir/dumps/Test_text_after_wrap_showbreak_10.dump b/src/testdir/dumps/Test_text_after_wrap_showbreak_10.dump
new file mode 100644 (file)
index 0000000..e1ab213
--- /dev/null
@@ -0,0 +1,8 @@
+> +8&#ffffff0@7|"| |1|2|3|4|5|6|7|8|$+8#4040ff13&|a+8#0000001#a8a8a8255
+|>+8#4040ff13#ffffff0| |a+8#0000001#a8a8a8255@2|8|9|0| |1|2|3| |4|5|6| |7|8|9
+|f+0#0000000#ffffff0|o@1|$+0#4040ff13&| +0#0000000&@15
+|b|a|r|$+0#4040ff13&| +0#0000000&@15
+|~+0#4040ff13&| @18
+|~| @18
+|~| @18
+| +0#0000000&@9|1|,|1| @2|A|l@1| 
diff --git a/src/testdir/dumps/Test_text_after_wrap_showbreak_11.dump b/src/testdir/dumps/Test_text_after_wrap_showbreak_11.dump
new file mode 100644 (file)
index 0000000..5a47901
--- /dev/null
@@ -0,0 +1,8 @@
+| +0&#ffffff0@7|"| |1|2|3|4|5|6|7|8|$+0#4040ff13&|a+0#0000001#a8a8a8255
+|>+0#4040ff13#ffffff0| |a+0#0000001#a8a8a8255@2|8|9|0| |1|2|3| |4|5|6| |7|8|9
+>f+8#0000000#ffffff0|o@1|$+8#4040ff13&| +8#0000000&@15
+|b+0&&|a|r|$+0#4040ff13&| +0#0000000&@15
+|~+0#4040ff13&| @18
+|~| @18
+|~| @18
+| +0#0000000&@9|2|,|1| @2|A|l@1| 
diff --git a/src/testdir/dumps/Test_text_after_wrap_showbreak_12.dump b/src/testdir/dumps/Test_text_after_wrap_showbreak_12.dump
new file mode 100644 (file)
index 0000000..dc5b3cc
--- /dev/null
@@ -0,0 +1,8 @@
+| +0&#ffffff0@7|"| |1|2|3|4|5|6|7|8|$+0#4040ff13&|a+0#0000001#a8a8a8255
+|>+0#4040ff13#ffffff0| |a+0#0000001#a8a8a8255@2|8|9|0| |1|2|3| |4|5|6| |7|8|9
+|f+0#0000000#ffffff0|o@1|$+0#4040ff13&| +0#0000000&@15
+>b+8&&|a|r|$+8#4040ff13&| +8#0000000&@15
+|~+0#4040ff13&| @18
+|~| @18
+|~| @18
+| +0#0000000&@9|3|,|1| @2|A|l@1| 
index b5c9f63f652f8d9e11df02da02d29ecfbc27df7d..5340aeef1fd8c32c86c2d0cc834131c0c2f61e8f 100644 (file)
@@ -4264,6 +4264,81 @@ func Test_text_after_nowrap_list()
   call StopVimInTerminal(buf)
 endfunc
 
+func Test_text_after_wrap_showbreak()
+  CheckScreendump
+  CheckRunVimInTerminal
+
+  let lines =<< trim END
+    set cursorline
+    set shiftwidth=4
+
+    set breakindent
+    set showbreak=>\ 
+    set breakindentopt=shift:2,min:64
+
+    call setline(1, ['        " 1234567890', 'foo', 'bar'])
+
+    call prop_type_add('Test', {
+          \ 'highlight': 'Visual',
+          \ 'priority': 10,
+          \ 'combine': v:true,
+          \ })
+    call prop_add(1, 0, #{
+          \ type: 'Test',
+          \ bufnr: bufnr('%'),
+          \ text: 'aaaa890 123 456 789',
+          \ text_wrap: 'wrap',
+          \ text_align: 'after'
+          \ })
+  END
+  call writefile(lines, 'XTestAfterWrapShowbreak', 'D')
+  let buf = RunVimInTerminal('-S XTestAfterWrapShowbreak', #{rows: 8, cols: 20})
+  call VerifyScreenDump(buf, 'Test_text_after_wrap_showbreak_01', {})
+  call term_sendkeys(buf, 'j')
+  call VerifyScreenDump(buf, 'Test_text_after_wrap_showbreak_02', {})
+  call term_sendkeys(buf, 'j')
+  call VerifyScreenDump(buf, 'Test_text_after_wrap_showbreak_03', {})
+  call term_sendkeys(buf, 'k')
+  call VerifyScreenDump(buf, 'Test_text_after_wrap_showbreak_02', {})
+  call term_sendkeys(buf, 'k')
+  call VerifyScreenDump(buf, 'Test_text_after_wrap_showbreak_01', {})
+
+  call term_sendkeys(buf, '$x0')
+  call VerifyScreenDump(buf, 'Test_text_after_wrap_showbreak_04', {})
+  call term_sendkeys(buf, 'j')
+  call VerifyScreenDump(buf, 'Test_text_after_wrap_showbreak_05', {})
+  call term_sendkeys(buf, 'j')
+  call VerifyScreenDump(buf, 'Test_text_after_wrap_showbreak_06', {})
+  call term_sendkeys(buf, 'k')
+  call VerifyScreenDump(buf, 'Test_text_after_wrap_showbreak_05', {})
+  call term_sendkeys(buf, 'k')
+  call VerifyScreenDump(buf, 'Test_text_after_wrap_showbreak_04', {})
+
+  call term_sendkeys(buf, ":set list listchars=eol:$\<CR>")
+  call VerifyScreenDump(buf, 'Test_text_after_wrap_showbreak_07', {})
+  call term_sendkeys(buf, 'j')
+  call VerifyScreenDump(buf, 'Test_text_after_wrap_showbreak_08', {})
+  call term_sendkeys(buf, 'j')
+  call VerifyScreenDump(buf, 'Test_text_after_wrap_showbreak_09', {})
+  call term_sendkeys(buf, 'k')
+  call VerifyScreenDump(buf, 'Test_text_after_wrap_showbreak_08', {})
+  call term_sendkeys(buf, 'k')
+  call VerifyScreenDump(buf, 'Test_text_after_wrap_showbreak_07', {})
+
+  call term_sendkeys(buf, '$x0')
+  call VerifyScreenDump(buf, 'Test_text_after_wrap_showbreak_10', {})
+  call term_sendkeys(buf, 'j')
+  call VerifyScreenDump(buf, 'Test_text_after_wrap_showbreak_11', {})
+  call term_sendkeys(buf, 'j')
+  call VerifyScreenDump(buf, 'Test_text_after_wrap_showbreak_12', {})
+  call term_sendkeys(buf, 'k')
+  call VerifyScreenDump(buf, 'Test_text_after_wrap_showbreak_11', {})
+  call term_sendkeys(buf, 'k')
+  call VerifyScreenDump(buf, 'Test_text_after_wrap_showbreak_10', {})
+
+  call StopVimInTerminal(buf)
+endfunc
+
 func Test_text_below_nowrap()
   CheckScreendump
   CheckRunVimInTerminal
index e093873703a631cc83031a622aa025d7efb0a18a..4d820a9cb4e6bc40ac01011e5afb0eca99158d8f 100644 (file)
@@ -729,6 +729,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1796,
 /**/
     1795,
 /**/