Skip to content

Commit 74ede80

Browse files
committed
patch 8.2.2904: "g$" causes scroll if half a double width char is visible
Problem: "g$" causes scroll if half a double width char is visible. Solution: Advance to the last fully visible character. (closes #8254)
1 parent a06e345 commit 74ede80

3 files changed

Lines changed: 38 additions & 3 deletions

File tree

src/normal.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6144,6 +6144,17 @@ nv_g_cmd(cmdarg_T *cap)
61446144
i = curwin->w_leftcol + curwin->w_width - col_off - 1;
61456145
coladvance((colnr_T)i);
61466146

6147+
// if the character doesn't fit move one back
6148+
if (curwin->w_cursor.col > 0
6149+
&& (*mb_ptr2cells)(ml_get_cursor()) > 1)
6150+
{
6151+
colnr_T vcol;
6152+
6153+
getvvcol(curwin, &curwin->w_cursor, NULL, NULL, &vcol);
6154+
if (vcol >= curwin->w_leftcol + curwin->w_width - col_off)
6155+
--curwin->w_cursor.col;
6156+
}
6157+
61476158
// Make sure we stick in this column.
61486159
validate_virtcol();
61496160
curwin->w_curswant = curwin->w_virtcol;

src/testdir/test_normal.vim

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2201,9 +2201,9 @@ func Test_normal33_g_cmd2()
22012201
%d
22022202
15vsp
22032203
set wrap listchars= sbr=
2204-
let lineA='abcdefghijklmnopqrstuvwxyz'
2205-
let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
2206-
let lineC='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
2204+
let lineA = 'abcdefghijklmnopqrstuvwxyz'
2205+
let lineB = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
2206+
let lineC = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
22072207
$put =lineA
22082208
$put =lineB
22092209

@@ -2238,6 +2238,28 @@ func Test_normal33_g_cmd2()
22382238
call assert_equal('l', getreg(0))
22392239
call assert_beeps('normal 5g$')
22402240

2241+
" Test for g$ with double-width character half displayed
2242+
vsplit
2243+
9wincmd |
2244+
setlocal nowrap nonumber
2245+
call setline(2, 'asdfasdfヨ')
2246+
2
2247+
normal 0g$
2248+
call assert_equal(8, col('.'))
2249+
10wincmd |
2250+
normal 0g$
2251+
call assert_equal(9, col('.'))
2252+
2253+
setlocal signcolumn=yes
2254+
11wincmd |
2255+
normal 0g$
2256+
call assert_equal(8, col('.'))
2257+
12wincmd |
2258+
normal 0g$
2259+
call assert_equal(9, col('.'))
2260+
2261+
close
2262+
22412263
" Test for g_
22422264
call assert_beeps('normal! 100g_')
22432265
call setline(2, [' foo ', ' foobar '])

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2904,
753755
/**/
754756
2903,
755757
/**/

0 commit comments

Comments
 (0)