]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1890: %P in 'statusline' doesn't behave as documented v9.1.1890
authorzeertzjq <zeertzjq@outlook.com>
Fri, 31 Oct 2025 09:10:05 +0000 (09:10 +0000)
committerChristian Brabandt <cb@256bit.org>
Fri, 31 Oct 2025 09:10:05 +0000 (09:10 +0000)
Problem:  %P in 'statusline' doesn't behave as documented
          (after 9.1.1479).
Solution: Make the percentage 3-chars wide when not translated.
          (zeertzjq)

fixes: #18669
closes: #18671

Co-authored-by: Christ van Willegen <cvwillegen@gmail.com>
Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/buffer.c
src/testdir/test_statusline.vim
src/version.c

index 548df80516461ca320f0376ec4c33c838453c966..6e4990abdfc7561d671e39326e351fa6a127721d 100644 (file)
@@ -5430,7 +5430,7 @@ get_rel_pos(
     char tmp[8];
     // localized percentage value
     vim_snprintf(tmp, sizeof(tmp), _("%d%%"), perc);
-    return (int)vim_snprintf_safelen((char *)buf, buflen, _("%2s"), tmp);
+    return (int)vim_snprintf_safelen((char *)buf, buflen, _("%3s"), tmp);
 }
 
 /*
index 9aa6aef6648a183700dfbd411cb7ef088122143b..4899bd0a05fb79f9c86561120c060ac36b34370f 100644 (file)
@@ -168,9 +168,16 @@ func Test_statusline()
   call assert_match('^0,Top\s*$', s:get_statusline())
   norm G
   call assert_match('^100,Bot\s*$', s:get_statusline())
-  9000
-  " Don't check the exact percentage as it depends on the window size
-  call assert_match('^90,\(Top\|Bot\|\d\+%\)\s*$', s:get_statusline())
+  " The exact percentage depends on the window height, so create a window with
+  " known height.
+  9000 | botright 10split | setlocal scrolloff=0 | normal! zb
+  call assert_match('^90,89%\s*$', s:get_statusline())
+  normal! zt
+  call assert_match('^90,90%\s*$', s:get_statusline())
+  " %P should result in a string with 3 in length when not translated.
+  normal! 500zb
+  call assert_match('^5, 4%\s*$', s:get_statusline())
+  close
 
   " %q: "[Quickfix List]", "[Location List]" or empty.
   set statusline=%q
index 4e0477dd9fb8940a456fe7e74b45d43875f3ff22..5af88e6115c5b3c08f05f6e597397a959f329d40 100644 (file)
@@ -729,6 +729,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1890,
 /**/
     1889,
 /**/