aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-07-05 16:25:34 +0800
committerzeertzjq <zeertzjq@outlook.com>2022-07-05 17:32:42 +0800
commitf42657cbcf0e5775692b57e25591d42844a81934 (patch)
tree73a72d8cb48eb361169e987b89cc906205ebdb2a
parentd0835617facc98daf79318e26d41669bb2ce1a6b (diff)
downloadrneovim-f42657cbcf0e5775692b57e25591d42844a81934.tar.gz
rneovim-f42657cbcf0e5775692b57e25591d42844a81934.tar.bz2
rneovim-f42657cbcf0e5775692b57e25591d42844a81934.zip
vim-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 vim/vim#8254) https://github.com/vim/vim/commit/74ede80aeb272ac81d41a256057c4f250372dd00
-rw-r--r--src/nvim/normal.c10
-rw-r--r--src/nvim/testdir/test_normal.vim28
2 files changed, 35 insertions, 3 deletions
diff --git a/src/nvim/normal.c b/src/nvim/normal.c
index c7f7b569e7..ae4372da89 100644
--- a/src/nvim/normal.c
+++ b/src/nvim/normal.c
@@ -6157,6 +6157,16 @@ static void nv_g_cmd(cmdarg_T *cap)
i = curwin->w_leftcol + curwin->w_width_inner - col_off - 1;
coladvance((colnr_T)i);
+ // if the character doesn't fit move one back
+ if (curwin->w_cursor.col > 0 && utf_ptr2cells((const char *)get_cursor_pos_ptr()) > 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;
diff --git a/src/nvim/testdir/test_normal.vim b/src/nvim/testdir/test_normal.vim
index 789ca747b4..9e7db91f25 100644
--- a/src/nvim/testdir/test_normal.vim
+++ b/src/nvim/testdir/test_normal.vim
@@ -1784,9 +1784,9 @@ fun! 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
@@ -1821,6 +1821,28 @@ fun! 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 '])