]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.2102: foldtext not reversed and cut off in 'rightleft' mode v9.1.2102
authorSergey Vlasov <sergey@vlasov.me>
Wed, 21 Jan 2026 19:48:46 +0000 (19:48 +0000)
committerChristian Brabandt <cb@256bit.org>
Wed, 21 Jan 2026 19:48:46 +0000 (19:48 +0000)
Problem:  foldtext not reversed and cut off in 'rightleft' mode
          (bfredl)
Solution: Fix the rightleft redrawing logic (Sergey Vlasov)

fixes:  #2659
closes: #19220

Signed-off-by: Sergey Vlasov <sergey@vlasov.me>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/drawscreen.c
src/testdir/dumps/Test_foldtext_and_fillchars_rightleft_01.dump [new file with mode: 0644]
src/testdir/dumps/Test_foldtext_and_fillchars_rightleft_02.dump [new file with mode: 0644]
src/testdir/test_fold.vim
src/version.c

index 79c0483e1817dcc729665268d2610c0314e51a87..1124840816848bc002815e0ed13307b212197c1f 100644 (file)
@@ -898,12 +898,12 @@ text_to_screenline(win_T *wp, char_u *text, int col)
        {
            cells = (*mb_ptr2cells)(p);
            c_len = (*mb_ptr2len)(p);
-           if (col + cells > wp->w_width
+           if (col + cells > wp->w_width)
+               break;
 # ifdef FEAT_RIGHTLEFT
-                   - (wp->w_p_rl ? col : 0)
+           if (wp->w_p_rl)
+               idx = off + wp->w_width - col - cells;
 # endif
-                   )
-               break;
            ScreenLines[idx] = *p;
            if (enc_utf8)
            {
@@ -1270,35 +1270,33 @@ fold_line(
     col = text_to_screenline(wp, text, col);
 
     // Fill the rest of the line with the fold filler
-# ifdef FEAT_RIGHTLEFT
-    if (wp->w_p_rl)
-       col -= txtcol;
-# endif
-    while (col < wp->w_width
-# ifdef FEAT_RIGHTLEFT
-                   - (wp->w_p_rl ? txtcol : 0)
-# endif
-           )
+    while (col < wp->w_width)
     {
        int c = wp->w_fill_chars.fold;
+       int idx = off + col;
+
+# ifdef FEAT_RIGHTLEFT
+       if (wp->w_p_rl)
+           idx = off + wp->w_width - 1 - col;
+# endif
 
        if (enc_utf8)
        {
            if (c >= 0x80)
            {
-               ScreenLinesUC[off + col] = c;
-               ScreenLinesC[0][off + col] = 0;
-               ScreenLines[off + col] = 0x80; // avoid storing zero
+               ScreenLinesUC[idx] = c;
+               ScreenLinesC[0][idx] = 0;
+               ScreenLines[idx] = 0x80; // avoid storing zero
            }
            else
            {
-               ScreenLinesUC[off + col] = 0;
-               ScreenLines[off + col] = c;
+               ScreenLinesUC[idx] = 0;
+               ScreenLines[idx] = c;
            }
-           col++;
        }
        else
-           ScreenLines[off + col++] = c;
+           ScreenLines[idx] = c;
+       ++col;
     }
 
     if (text != buf)
diff --git a/src/testdir/dumps/Test_foldtext_and_fillchars_rightleft_01.dump b/src/testdir/dumps/Test_foldtext_and_fillchars_rightleft_01.dump
new file mode 100644 (file)
index 0000000..b1892c0
--- /dev/null
@@ -0,0 +1,5 @@
+|-+0#0000e05#a8a8a8255@5|g|n|i|c|s|i|p|i|d|a| |r|u|t|e|t|c|e|s|n|o|c| |,|t|e|m|a| |t|i|s| |r|o|l|o|d| |m|u|s|p|i| |m|e|r|o|L| |:|s|e|n|i|l| |2| @1|-@1>+
+| +0#0000000#ffffff0@19|g|n|i|c|s|i|p|i|d|a| |r|u|t|e|t|c|e|s|n|o|c| |,|t|e|m|a| |t|i|s| |r|o|l|o|d| |m|u|s|p|i| |m|e|r|o|L
+| +0#4040ff13&@68|~
+| @68|~
+| +0#0000000&@51|1|,|1| @10|A|l@1| 
diff --git a/src/testdir/dumps/Test_foldtext_and_fillchars_rightleft_02.dump b/src/testdir/dumps/Test_foldtext_and_fillchars_rightleft_02.dump
new file mode 100644 (file)
index 0000000..1f401ec
--- /dev/null
@@ -0,0 +1,5 @@
+|-+0#0000e05#a8a8a8255@7|t*&|e|m|a| +&|t*&|i|s| +&|r*&|o|l|o|d| +&|m*&|u|s|p|i| +&|m*&|e|r|o|L| +&|:|s|e|n|i|l| |2| @1|->-|+
+| +0#0000000#ffffff0@21|t*&|e|m|a| +&|t*&|i|s| +&|r*&|o|l|o|d| +&|m*&|u|s|p|i| +&|m*&|e|r|o|L
+| +0#4040ff13&@68|~
+| @68|~
+|:+0#0000000&|c|a|l@1| |s|e|t|l|i|n|e|(|1|,| |[|g|:|m|u|l|t|i|b|y|t|e|,| |g|:|m|u|l|t|i|b|y|t|e|,| |g|:|m|u|l|t|i|b|1|,|1| @10|A|l@1| 
index 5ba2e81f345e72085de5b129b6c622640bab582a..56b6aaece04b00f0dbf875868137a982b5b3ec6f 100644 (file)
@@ -1473,6 +1473,54 @@ func Test_foldtextresult()
   bw!
 endfunc
 
+" Test for foldtext and fillchars with 'rightleft' enabled
+func Test_foldtext_and_fillchars_rightleft()
+  CheckFeature rightleft
+  CheckScreendump
+  CheckRunVimInTerminal
+
+  let script_lines =<< trim END
+    let longtext = 'Lorem ipsum dolor sit amet, consectetur adipiscing'
+    let g:multibyte = 'Lorem ipsum dolor sit amet'
+
+    call setline(1, [longtext, longtext, longtext])
+    1,2fold
+
+    setlocal rightleft
+    set noshowmode noshowcmd
+  END
+  call writefile(script_lines, 'XTest_foldtext_and_fillchars_rightleft', 'D')
+  let buf = RunVimInTerminal('-S XTest_foldtext_and_fillchars_rightleft', {'rows': 5, 'cols': 70})
+
+  call VerifyScreenDump(buf, 'Test_foldtext_and_fillchars_rightleft_01', {})
+  call term_sendkeys(buf, ":call setline(1, [g:multibyte, g:multibyte, g:multibyte])\<CR>")
+  call VerifyScreenDump(buf, 'Test_foldtext_and_fillchars_rightleft_02', {})
+
+  " clean up
+  call StopVimInTerminal(buf)
+endfunc
+
+" Test for foldtextresult() with 'rightleft' enabled
+func Test_foldtextresult_rightleft()
+  CheckFeature rightleft
+
+  new
+  set columns=70
+  setlocal rightleft
+
+  let longtext = 'Lorem ipsum dolor sit amet, consectetur adipiscing'
+  let multibyte = 'Lorem ipsum dolor sit amet'
+
+  call setline(1, [longtext, longtext, longtext])
+  1,2fold
+  call assert_equal('+--  2 lines: ' .. longtext, foldtextresult(1))
+
+  call setline(1, [multibyte, multibyte, multibyte])
+  call assert_equal('+--  2 lines: ' .. multibyte, foldtextresult(1))
+
+  bw!
+endfunc
+
 " Test for merging two recursive folds when an intermediate line with no fold
 " is removed
 func Test_fold_merge_recursive()
index d6644bf10c378664170dd67962cb8f06070bda15..b893c9ad2543d92c86b5b9549dc9791787982e3b 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2102,
 /**/
     2101,
 /**/