]> granicus.if.org Git - vim/commitdiff
patch 9.0.0716: with 'nowrap' virtual text "after" does not scroll left v9.0.0716
authorBram Moolenaar <Bram@vim.org>
Mon, 10 Oct 2022 18:50:42 +0000 (19:50 +0100)
committerBram Moolenaar <Bram@vim.org>
Mon, 10 Oct 2022 18:50:42 +0000 (19:50 +0100)
Problem:    With 'nowrap' virtual text "after" does not scroll left.
Solution:   Skip part of the virtual text that is left of the window.
            (closes #11320)  Fix going beyond the last column of the window.

src/drawline.c
src/testdir/dumps/Test_text_after_nowrap_1.dump
src/testdir/dumps/Test_text_after_nowrap_2.dump [new file with mode: 0644]
src/testdir/dumps/Test_text_after_nowrap_3.dump [new file with mode: 0644]
src/testdir/dumps/Test_text_after_nowrap_4.dump [new file with mode: 0644]
src/testdir/test_textprop.vim
src/version.c

index 9aad81b9cccdb87f82d3b610828b5cce03688895..f02e4f3a2fc027d2e11653a79a5aaeb2df652bec 100644 (file)
@@ -975,7 +975,11 @@ win_line(
     int                n_attr3 = 0;        // chars with overruling special attr
     int                saved_attr3 = 0;    // char_attr saved for n_attr3
 
-    int                n_skip = 0;             // nr of chars to skip for 'nowrap'
+    int                n_skip = 0;             // nr of cells to skip for 'nowrap' or
+                                       // concealing
+    int                skip_cells = 0;         // nr of cells to skip for virtual text
+                                       // after the line, when w_skipcol is
+                                       // larger than the text length
 
     int                fromcol_prev = -2;      // start of inverting after cursor
     int                noinvcur = FALSE;       // don't invert the cursor
@@ -1504,6 +1508,11 @@ win_line(
               n_skip = v - wlv.vcol;
        }
 
+       // If there the text doesn't reach to the desired column, need to skip
+       // "skip_cells" cells when virtual text follows.
+       if (!wp->w_p_wrap && v > wlv.vcol)
+           skip_cells = v - wlv.vcol;
+
        // Adjust for when the inverted text is before the screen,
        // and when the start of the inverted text is before the screen.
        if (wlv.tocol <= wlv.vcol)
@@ -1897,10 +1906,20 @@ win_line(
                        int         tpi = text_prop_idxs[pi];
                        textprop_T  *tp = &text_props[tpi];
                        proptype_T  *pt = text_prop_type_by_id(
-                                       wp->w_buffer, tp->tp_type);
-
-                       if (pt != NULL && (pt->pt_hl_id > 0
-                                    || tp->tp_id < 0) && tp->tp_id != -MAXCOL)
+                                                   wp->w_buffer, tp->tp_type);
+
+                       // Only use a text property that can be displayed.
+                       // Skip "after" properties when wrap is off and at the
+                       // end of the window.
+                       if (pt != NULL
+                               && (pt->pt_hl_id > 0 || tp->tp_id < 0)
+                               && tp->tp_id != -MAXCOL
+                               && !(tp->tp_id < 0
+                                   && !wp->w_p_wrap
+                                   && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
+                                               | TP_FLAG_ALIGN_ABOVE
+                                               | TP_FLAG_ALIGN_BELOW)) == 0
+                                   && wlv.col >= wp->w_width))
                        {
                            if (pt->pt_hl_id > 0)
                                used_attr = syn_id2attr(pt->pt_hl_id);
@@ -2015,6 +2034,30 @@ win_line(
                            }
                        }
 
+                       // If the text didn't reach until the first window
+                       // column we need to skip cells.
+                       if (skip_cells > 0)
+                       {
+                           if (wlv.n_extra > skip_cells)
+                           {
+                               wlv.n_extra -= skip_cells;
+                               wlv.p_extra += skip_cells;
+                               n_attr_skip -= skip_cells;
+                               if (n_attr_skip < 0)
+                                   n_attr_skip = 0;
+                               skip_cells = 0;
+                           }
+                           else
+                           {
+                               // the whole text is left of the window, drop
+                               // it and advance to the next one
+                               skip_cells -= wlv.n_extra;
+                               wlv.n_extra = 0;
+                               n_attr_skip = 0;
+                               bail_out = TRUE;
+                           }
+                       }
+
                        // If another text prop follows the condition below at
                        // the last window column must know.
                        // If this is an "above" text prop and 'nowrap' the we
index d8711b84ca6a46b78a4c0b62643a85e42bbd17ce..0781e6cde07e211792194af3cd3675ec39f0aac9 100644 (file)
@@ -1,8 +1,8 @@
-|f+0&#ffffff0|i|r|s|t| |l|i|n|e| @1|a+0&#ffd7ff255|f|t|e|r| |t|h|e| |t|e|x|t| |a|f|t|e|r| |t|h|e| |t|e|x|t| |a|f|t|e|r| |t|h|e| |t|e|x|t| |a|f|t
-|s+0&#ffffff0|e|c|o|n|d| >l|i|n|e| |s|e|c|o|n|d| |l|i|n|e| |s|e|c|o|n|d| |l|i|n|e| |s|e|c|o|n|d| |l|i|n|e| |s|e|c|o|n|d| |l|i|n|e| 
+|f+0&#ffffff0|i|r|s|t| |l|i|n|e| @1|r+0&#ffd7ff255|i|g|h|t| |a|f|t|e|r| |t|h|e| |t|e|x|t| |r|i|g|h|t| |a|f|t|e|r| |t|h|e| |t|e|x|t| |r|i|g|h|t| 
+|0+0&#ffffff0| >1| |2| |3| |4| |5| |6| |7| |8| |9| |1|0| |1@1| |1|2| |1|3| |1|4| |1|5| |1|6| |1|7| |1|8| |1|9| |2|0| |2|1| |2@1| |2
 |t|h|i|r|d| @54
 |f|o|u|r|t|h| @53
 |~+0#4040ff13&| @58
 |~| @58
 |~| @58
-| +0#0000000&@41|2|,|8| @10|A|l@1| 
+| +0#0000000&@41|2|,|3| @10|A|l@1| 
diff --git a/src/testdir/dumps/Test_text_after_nowrap_2.dump b/src/testdir/dumps/Test_text_after_nowrap_2.dump
new file mode 100644 (file)
index 0000000..28a45f3
--- /dev/null
@@ -0,0 +1,8 @@
+| +0&#ffd7ff255|r|i|g|h|t| |a|f|t|e|r| |t|h|e| | +0&#ffffff0@2|i+0&#ffd7ff255|n| |t|h|e| |m|i|d@1|l|e| |i|n| |t|h|e| |m|i|d@1|l|e| |i|n| |t|h|e| |m|i|d@1|l
+|2+0&#ffffff0|1| |2@1| |2|3| |2|4| |2|5| |2|6| |2|7| |2|8| |2|9| |3|0| >3|1| |3|2| |3@1| |3|4| |3|5| |3|6| |3|7| |3|8| |3|9| |4|0| 
+@60
+@60
+|~+0#4040ff13&| @58
+|~| @58
+|~| @58
+| +0#0000000&@41|2|,|8|4| @9|A|l@1| 
diff --git a/src/testdir/dumps/Test_text_after_nowrap_3.dump b/src/testdir/dumps/Test_text_after_nowrap_3.dump
new file mode 100644 (file)
index 0000000..0a7cb3b
--- /dev/null
@@ -0,0 +1,8 @@
+|h+0&#ffd7ff255|e| |m|i|d@1|l|e| | +0&#ffffff0|t+0&#ffd7ff255|h|e| |l|a|s|t| |o|n|e| |t|h|e| |l|a|s|t| |o|n|e| |t|h|e| |l|a|s|t| |o|n|e| | +0&#ffffff0@9
+|4|3| |4@1| |4|5| |4|6| |4|7| |4|8| |4|9| |5|0| |5|1| |5|2| >5|3| |5|4| |5@1| |5|6| |5|7| |5|8| |5|9| |6|0| |6|1| |6|2| 
+@60
+@60
+|~+0#4040ff13&| @58
+|~| @58
+|~| @58
+| +0#0000000&@41|2|,|1|5|0| @8|A|l@1| 
diff --git a/src/testdir/dumps/Test_text_after_nowrap_4.dump b/src/testdir/dumps/Test_text_after_nowrap_4.dump
new file mode 100644 (file)
index 0000000..ffe1c76
--- /dev/null
@@ -0,0 +1,8 @@
+| +0&#ffffff0@59
+|9| |7|0| |7|1| |7|2| |7|3| |7|4| |7|5| |7|6| |7@1| |7|8| |7>9| @28
+@60
+@60
+|~+0#4040ff13&| @58
+|~| @58
+|~| @58
+| +0#0000000&@41|2|,|2@1|9| @8|A|l@1| 
index 624f23fbfbd3e3f31364241a57ca7ec71763922f..b4178e5f25432c81254ed431f3c1aadcf9a294f1 100644 (file)
@@ -3214,30 +3214,44 @@ endfunc
 func Test_text_after_nowrap()
   CheckRunVimInTerminal
 
-  " FIXME: the second property causes a hang
   let lines =<< trim END
       vim9script
-      setline(1, ['first line', 'second line '->repeat(50), 'third', 'fourth'])
+      setline(1, ['first line', range(80)->join(' '), 'third', 'fourth'])
       set nowrap
       prop_type_add('theprop', {highlight: 'DiffChange'})
       prop_add(1, 0, {
           type: 'theprop',
-          text: 'after the text '->repeat(5),
+          text: 'right after the text '->repeat(3),
           text_align: 'after',
           text_padding_left: 2,
       })
-      #prop_add(1, 0, {
-      #    type: 'theprop',
-      #    text: 'after the text '->repeat(5),
-      #    text_align: 'after',
-      #    text_padding_left: 2,
-      #})
+      prop_add(1, 0, {
+          type: 'theprop',
+          text: 'in the middle '->repeat(4),
+          text_align: 'after',
+          text_padding_left: 3,
+      })
+      prop_add(1, 0, {
+          type: 'theprop',
+          text: 'the last one '->repeat(3),
+          text_align: 'after',
+          text_padding_left: 1,
+      })
       normal 2Gw
   END
   call writefile(lines, 'XTextAfterNowrap', 'D')
   let buf = RunVimInTerminal('-S XTextAfterNowrap', #{rows: 8, cols: 60})
   call VerifyScreenDump(buf, 'Test_text_after_nowrap_1', {})
 
+  call term_sendkeys(buf, "30w")
+  call VerifyScreenDump(buf, 'Test_text_after_nowrap_2', {})
+
+  call term_sendkeys(buf, "22w")
+  call VerifyScreenDump(buf, 'Test_text_after_nowrap_3', {})
+
+  call term_sendkeys(buf, "$")
+  call VerifyScreenDump(buf, 'Test_text_after_nowrap_4', {})
+
   call StopVimInTerminal(buf)
 endfunc
 
index 564d69d8df5cc101ab918f6262b4ff912122fbf0..bfdd1faec82beb3068b6e65414f207649896f9a9 100644 (file)
@@ -699,6 +699,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    716,
 /**/
     715,
 /**/