mirror of
https://github.com/neovim/neovim.git
synced 2025-09-07 20:08:17 +00:00
vim-patch:8.2.2385: "gj" and "gk" do not work correctly when inside a fold
Problem: "gj" and "gk" do not work correctly when inside a fold.
Solution: Move check for folding. (closes vim/vim#7724, closes vim/vim#4095)
e71996bd08
This commit is contained in:
@@ -3978,16 +3978,19 @@ static bool nv_screengo(oparg_T *oap, int dir, long dist)
|
|||||||
curwin->w_curswant -= width2;
|
curwin->w_curswant -= width2;
|
||||||
} else {
|
} else {
|
||||||
// to previous line
|
// to previous line
|
||||||
|
|
||||||
|
// Move to the start of a closed fold. Don't do that when
|
||||||
|
// 'foldopen' contains "all": it will open in a moment.
|
||||||
|
if (!(fdo_flags & FDO_ALL)) {
|
||||||
|
(void)hasFolding(curwin->w_cursor.lnum,
|
||||||
|
&curwin->w_cursor.lnum, NULL);
|
||||||
|
}
|
||||||
if (curwin->w_cursor.lnum == 1) {
|
if (curwin->w_cursor.lnum == 1) {
|
||||||
retval = false;
|
retval = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
--curwin->w_cursor.lnum;
|
curwin->w_cursor.lnum--;
|
||||||
/* Move to the start of a closed fold. Don't do that when
|
|
||||||
* 'foldopen' contains "all": it will open in a moment. */
|
|
||||||
if (!(fdo_flags & FDO_ALL))
|
|
||||||
(void)hasFolding(curwin->w_cursor.lnum,
|
|
||||||
&curwin->w_cursor.lnum, NULL);
|
|
||||||
linelen = linetabsize(get_cursor_line_ptr());
|
linelen = linetabsize(get_cursor_line_ptr());
|
||||||
if (linelen > width1) {
|
if (linelen > width1) {
|
||||||
int w = (((linelen - width1 - 1) / width2) + 1) * width2;
|
int w = (((linelen - width1 - 1) / width2) + 1) * width2;
|
||||||
@@ -6708,11 +6711,8 @@ static void nv_g_cmd(cmdarg_T *cap)
|
|||||||
*/
|
*/
|
||||||
case 'j':
|
case 'j':
|
||||||
case K_DOWN:
|
case K_DOWN:
|
||||||
/* with 'nowrap' it works just like the normal "j" command; also when
|
// with 'nowrap' it works just like the normal "j" command.
|
||||||
* in a closed fold */
|
if (!curwin->w_p_wrap) {
|
||||||
if (!curwin->w_p_wrap
|
|
||||||
|| hasFolding(curwin->w_cursor.lnum, NULL, NULL)
|
|
||||||
) {
|
|
||||||
oap->motion_type = kMTLineWise;
|
oap->motion_type = kMTLineWise;
|
||||||
i = cursor_down(cap->count1, oap->op_type == OP_NOP);
|
i = cursor_down(cap->count1, oap->op_type == OP_NOP);
|
||||||
} else
|
} else
|
||||||
@@ -6723,11 +6723,8 @@ static void nv_g_cmd(cmdarg_T *cap)
|
|||||||
|
|
||||||
case 'k':
|
case 'k':
|
||||||
case K_UP:
|
case K_UP:
|
||||||
/* with 'nowrap' it works just like the normal "k" command; also when
|
// with 'nowrap' it works just like the normal "k" command.
|
||||||
* in a closed fold */
|
if (!curwin->w_p_wrap) {
|
||||||
if (!curwin->w_p_wrap
|
|
||||||
|| hasFolding(curwin->w_cursor.lnum, NULL, NULL)
|
|
||||||
) {
|
|
||||||
oap->motion_type = kMTLineWise;
|
oap->motion_type = kMTLineWise;
|
||||||
i = cursor_up(cap->count1, oap->op_type == OP_NOP);
|
i = cursor_up(cap->count1, oap->op_type == OP_NOP);
|
||||||
} else
|
} else
|
||||||
|
@@ -822,4 +822,39 @@ func Test_fold_create_delete()
|
|||||||
bwipe!
|
bwipe!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_fold_relative_move()
|
||||||
|
enew!
|
||||||
|
set fdm=indent sw=2 wrap tw=80
|
||||||
|
|
||||||
|
let content = [ ' foo', ' bar', ' baz',
|
||||||
|
\ repeat('x', 100),
|
||||||
|
\ ' foo', ' bar', ' baz'
|
||||||
|
\ ]
|
||||||
|
call append(0, content)
|
||||||
|
|
||||||
|
normal zM
|
||||||
|
|
||||||
|
call cursor(3, 1)
|
||||||
|
call assert_true(foldclosed(line('.')))
|
||||||
|
normal gj
|
||||||
|
call assert_equal(2, winline())
|
||||||
|
|
||||||
|
call cursor(2, 1)
|
||||||
|
call assert_true(foldclosed(line('.')))
|
||||||
|
normal 2gj
|
||||||
|
call assert_equal(3, winline())
|
||||||
|
|
||||||
|
call cursor(5, 1)
|
||||||
|
call assert_true(foldclosed(line('.')))
|
||||||
|
normal gk
|
||||||
|
call assert_equal(3, winline())
|
||||||
|
|
||||||
|
call cursor(6, 1)
|
||||||
|
call assert_true(foldclosed(line('.')))
|
||||||
|
normal 2gk
|
||||||
|
call assert_equal(2, winline())
|
||||||
|
|
||||||
|
set fdm& sw& wrap& tw&
|
||||||
|
endfunc
|
||||||
|
|
||||||
" vim: shiftwidth=2 sts=2 expandtab
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
Reference in New Issue
Block a user