diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-11-18 09:52:11 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-18 09:52:11 +0800 |
commit | 1763eddede82697a081d8741bd7e780c1b729de0 (patch) | |
tree | 073208c5f2bcdf3d4b9748476b606b486648ef02 | |
parent | 965dc81f818e50b5078d4b7efa5fbb8b771560f8 (diff) | |
download | rneovim-1763eddede82697a081d8741bd7e780c1b729de0.tar.gz rneovim-1763eddede82697a081d8741bd7e780c1b729de0.tar.bz2 rneovim-1763eddede82697a081d8741bd7e780c1b729de0.zip |
vim-patch:9.1.0869: Problem: curswant not set on gm in folded line (#31247)
Problem: curswant not set on gm in folded line
(citizenmatt)
Solution: in a folded line, call update_curswant_force()
fixes: vim/vim#11596
closes: vim/vim#11994
closes: vim/vim#15398
https://github.com/vim/vim/commit/9848face747ba91282d34a96dcb966bcb410bf2b
Co-authored-by: Christian Brabandt <cb@256bit.org>
-rw-r--r-- | src/nvim/normal.c | 6 | ||||
-rw-r--r-- | test/functional/legacy/normal_spec.lua | 29 | ||||
-rw-r--r-- | test/old/testdir/test_curswant.vim | 52 |
3 files changed, 85 insertions, 2 deletions
diff --git a/src/nvim/normal.c b/src/nvim/normal.c index d2716bf236..55aa385b33 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -5249,6 +5249,12 @@ void nv_g_home_m_cmd(cmdarg_T *cap) curwin->w_valid &= ~VALID_WCOL; } curwin->w_set_curswant = true; + if (hasAnyFolding(curwin)) { + validate_cheight(curwin); + if (curwin->w_cline_folded) { + update_curswant_force(); + } + } adjust_skipcol(); } diff --git a/test/functional/legacy/normal_spec.lua b/test/functional/legacy/normal_spec.lua index 717ebbba70..1ae22a83bd 100644 --- a/test/functional/legacy/normal_spec.lua +++ b/test/functional/legacy/normal_spec.lua @@ -102,4 +102,33 @@ describe('normal', function() ]], }) end) + + -- oldtest: Test_normal_gm() + it('gm sets curswant correctly', function() + screen:try_resize(75, 10) + exec([[ + call setline(1, repeat([" abcd\tefgh\tij"], 10)) + call cursor(1, 1) + ]]) + feed('jVjzf') + -- gm + feed('gmk') + eq(18, fn.virtcol('.')) + -- g0 + feed('gj0k') + eq(1, fn.virtcol('.')) + -- g^ + feed('jg^k') + eq(3, fn.virtcol('.')) + exec('call cursor(10, 1)') + -- gm + feed('gmk') + eq(18, fn.virtcol('.')) + -- g0 + feed('gj0k') + eq(1, fn.virtcol('.')) + -- g^ + feed('jg^k') + eq(3, fn.virtcol('.')) + end) end) diff --git a/test/old/testdir/test_curswant.vim b/test/old/testdir/test_curswant.vim index e54cd4b280..c67cca5f7d 100644 --- a/test/old/testdir/test_curswant.vim +++ b/test/old/testdir/test_curswant.vim @@ -1,4 +1,7 @@ -" Tests for curswant not changing when setting an option +" Tests for not changing curswant + +source check.vim +source term_util.vim func Test_curswant() new @@ -19,5 +22,50 @@ func Test_curswant() let &ttimeoutlen=&ttimeoutlen call assert_equal(7, winsaveview().curswant) - enew! + bw! +endfunc + +func Test_normal_gm() + CheckRunVimInTerminal + let lines =<< trim END + call setline(1, repeat([" abcd\tefgh\tij"], 10)) + call cursor(1, 1) + END + call writefile(lines, 'XtestCurswant', 'D') + let buf = RunVimInTerminal('-S XtestCurswant', #{rows: 10}) + if has("folding") + call term_sendkeys(buf, "jVjzf") + " gm + call term_sendkeys(buf, "gmk") + call term_sendkeys(buf, ":echo virtcol('.')\<cr>") + call WaitFor({-> term_getline(buf, 10) =~ '^18\s\+'}) + " g0 + call term_sendkeys(buf, "jg0k") + call term_sendkeys(buf, ":echo virtcol('.')\<cr>") + call WaitFor({-> term_getline(buf, 10) =~ '^1\s\+'}) + " g^ + call term_sendkeys(buf, "jg^k") + call term_sendkeys(buf, ":echo virtcol('.')\<cr>") + call WaitFor({-> term_getline(buf, 10) =~ '^3\s\+'}) + endif + call term_sendkeys(buf, ":call cursor(10, 1)\<cr>") + " gm + call term_sendkeys(buf, "gmk") + call term_sendkeys(buf, ":echo virtcol('.')\<cr>") + call term_wait(buf) + call WaitFor({-> term_getline(buf, 10) =~ '^18\s\+'}) + " g0 + call term_sendkeys(buf, "g0k") + call term_sendkeys(buf, ":echo virtcol('.')\<cr>") + call WaitFor({-> term_getline(buf, 10) =~ '^1\s\+'}) + " g^ + call term_sendkeys(buf, "g^k") + call term_sendkeys(buf, ":echo virtcol('.')\<cr>") + call WaitFor({-> term_getline(buf, 10) =~ '^3\s\+'}) + " clean up + call StopVimInTerminal(buf) + wincmd p + wincmd c endfunc + +" vim: shiftwidth=2 sts=2 expandtab |