]> granicus.if.org Git - vim/commitdiff
patch 8.2.2904: "g$" causes scroll if half a double width char is visible v8.2.2904
authorBram Moolenaar <Bram@vim.org>
Sat, 29 May 2021 17:18:01 +0000 (19:18 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 29 May 2021 17:18:01 +0000 (19:18 +0200)
Problem:    "g$" causes scroll if half a double width char is visible.
Solution:   Advance to the last fully visible character. (closes #8254)

src/normal.c
src/testdir/test_normal.vim
src/version.c

index 92135c18c3f1706f30f325b4c40cefe1924c91b5..a7b32c6499e5cb1c2a444f4c3b6a4d6e43354de1 100644 (file)
@@ -6144,6 +6144,17 @@ nv_g_cmd(cmdarg_T *cap)
                i = curwin->w_leftcol + curwin->w_width - col_off - 1;
                coladvance((colnr_T)i);
 
+               // if the character doesn't fit move one back
+               if (curwin->w_cursor.col > 0
+                                      && (*mb_ptr2cells)(ml_get_cursor()) > 1)
+               {
+                   colnr_T vcol;
+
+                   getvvcol(curwin, &curwin->w_cursor, NULL, NULL, &vcol);
+                   if (vcol >= curwin->w_leftcol + curwin->w_width - col_off)
+                       --curwin->w_cursor.col;
+               }
+
                // Make sure we stick in this column.
                validate_virtcol();
                curwin->w_curswant = curwin->w_virtcol;
index 72a7253ff44e1b547a01936163926d13ec78107f..f6e60a8ae5d184d31d1056c7f501db35752a151b 100644 (file)
@@ -2201,9 +2201,9 @@ func Test_normal33_g_cmd2()
   %d
   15vsp
   set wrap listchars= sbr=
-  let lineA='abcdefghijklmnopqrstuvwxyz'
-  let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
-  let lineC='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
+  let lineA = 'abcdefghijklmnopqrstuvwxyz'
+  let lineB = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+  let lineC = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
   $put =lineA
   $put =lineB
 
@@ -2238,6 +2238,28 @@ func Test_normal33_g_cmd2()
   call assert_equal('l', getreg(0))
   call assert_beeps('normal 5g$')
 
+  " Test for g$ with double-width character half displayed
+  vsplit
+  9wincmd |
+  setlocal nowrap nonumber
+  call setline(2, 'asdfasdfヨ')
+  2
+  normal 0g$
+  call assert_equal(8, col('.'))
+  10wincmd |
+  normal 0g$
+  call assert_equal(9, col('.'))
+
+  setlocal signcolumn=yes
+  11wincmd |
+  normal 0g$
+  call assert_equal(8, col('.'))
+  12wincmd |
+  normal 0g$
+  call assert_equal(9, col('.'))
+
+  close
+
   " Test for g_
   call assert_beeps('normal! 100g_')
   call setline(2, ['  foo  ', '  foobar  '])
index c94183bfdb7a1f622e8c52cfe040133f28a36ad7..b95a9690881d691e2591dc79934423c75d81bf54 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2904,
 /**/
     2903,
 /**/