From 3c740f7424f232792609320b2093bbbd899ab11b Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 2 Mar 2017 00:00:51 +0100 Subject: vim-patch:8.0.0135 Problem: An address relative to the current line, ":.,+3y", does not work properly on a closed fold. (Efraim Yawitz) Solution: Correct for including the closed fold. (Christian Brabandt) https://github.com/vim/vim/commit/ded2782783f352201ac0b05c6dbe4831adb4a58b --- src/nvim/ex_docmd.c | 28 ++++++---- src/nvim/testdir/test_fold.vim | 114 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+), 9 deletions(-) create mode 100644 src/nvim/testdir/test_fold.vim (limited to 'src/nvim') diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 03f943b1b1..ff0df9e51c 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -1244,6 +1244,7 @@ static char_u * do_one_cmd(char_u **cmdlinep, cmdmod_T save_cmdmod; int ni; /* set when Not Implemented */ char_u *cmd; + int address_count = 1; memset(&ea, 0, sizeof(ea)); ea.line1 = 1; @@ -1405,7 +1406,7 @@ static char_u * do_one_cmd(char_u **cmdlinep, continue; case 't': if (checkforcmd(&p, "tab", 3)) { - long tabnr = get_address(&ea, &ea.cmd, ADDR_TABS, ea.skip, false); + long tabnr = get_address(&ea, &ea.cmd, ADDR_TABS, ea.skip, false, 1); if (tabnr == MAXLNUM) { cmdmod.tab = tabpage_index(curtab) + 1; } else { @@ -1543,7 +1544,7 @@ static char_u * do_one_cmd(char_u **cmdlinep, } ea.cmd = skipwhite(ea.cmd); lnum = get_address(&ea, &ea.cmd, ea.addr_type, ea.skip, - ea.addr_count == 0); + ea.addr_count == 0, address_count++); if (ea.cmd == NULL) { // error detected goto doend; } @@ -3422,8 +3423,8 @@ static linenr_T get_address(exarg_T *eap, char_u **ptr, int addr_type, // flag: one of ADDR_LINES, ... int skip, // only skip the address, don't use it - int to_other_file // flag: may jump to other file - ) + int to_other_file, // flag: may jump to other file + int address_count) // 1 for first, >1 after comma { int c; int i; @@ -3656,10 +3657,19 @@ static linenr_T get_address(exarg_T *eap, if (addr_type == ADDR_LOADED_BUFFERS || addr_type == ADDR_BUFFERS) lnum = compute_buffer_local_count( addr_type, lnum, (i == '-') ? -1 * n : n); - else if (i == '-') - lnum -= n; - else - lnum += n; + else { + // Relative line addressing, need to adjust for folded lines + // now, but only do it after the first address. + if (addr_type == ADDR_LINES && (i == '-' || i == '+') + && address_count >= 2) { + (void)hasFolding(lnum, NULL, &lnum); + } + if (i == '-') { + lnum -= n; + } else { + lnum += n; + } + } } } while (*cmd == '/' || *cmd == '?'); @@ -7237,7 +7247,7 @@ static void ex_put(exarg_T *eap) */ static void ex_copymove(exarg_T *eap) { - long n = get_address(eap, &eap->arg, eap->addr_type, false, false); + long n = get_address(eap, &eap->arg, eap->addr_type, false, false, 1); if (eap->arg == NULL) { // error detected eap->nextcmd = NULL; return; diff --git a/src/nvim/testdir/test_fold.vim b/src/nvim/testdir/test_fold.vim new file mode 100644 index 0000000000..1f835b876f --- /dev/null +++ b/src/nvim/testdir/test_fold.vim @@ -0,0 +1,114 @@ +" Test for folding + +func! Test_address_fold() + new + call setline(1, ['int FuncName() {/*{{{*/', 1, 2, 3, 4, 5, '}/*}}}*/', + \ 'after fold 1', 'after fold 2', 'after fold 3']) + setl fen fdm=marker + " The next ccommands should all copy the same part of the buffer, + " regardless of the adressing type, since the part to be copied + " is folded away + :1y + call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1)) + :.y + call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1)) + :.+y + call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1)) + :.,.y + call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1)) + :sil .1,.y + call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1)) + " use silent to make E493 go away + :sil .+,.y + call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1)) + :,y + call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1)) + :,+y + call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/','after fold 1'], getreg(0,1,1)) + " using .+3 as second address should copy the whole folded line + the next 3 + " lines + :.,+3y + call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/', + \ 'after fold 1', 'after fold 2', 'after fold 3'], getreg(0,1,1)) + :sil .,-2y + call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1)) + + " now test again with folding disabled + set nofoldenable + :1y + call assert_equal(['int FuncName() {/*{{{*/'], getreg(0,1,1)) + :.y + call assert_equal(['int FuncName() {/*{{{*/'], getreg(0,1,1)) + :.+y + call assert_equal(['1'], getreg(0,1,1)) + :.,.y + call assert_equal(['int FuncName() {/*{{{*/'], getreg(0,1,1)) + " use silent to make E493 go away + :sil .1,.y + call assert_equal(['int FuncName() {/*{{{*/', '1'], getreg(0,1,1)) + " use silent to make E493 go away + :sil .+,.y + call assert_equal(['int FuncName() {/*{{{*/', '1'], getreg(0,1,1)) + :,y + call assert_equal(['int FuncName() {/*{{{*/'], getreg(0,1,1)) + :,+y + call assert_equal(['int FuncName() {/*{{{*/', '1'], getreg(0,1,1)) + " using .+3 as second address should copy the whole folded line + the next 3 + " lines + :.,+3y + call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3'], getreg(0,1,1)) + :7 + :sil .,-2y + call assert_equal(['4', '5', '}/*}}}*/'], getreg(0,1,1)) + + quit! +endfunc + +func! Test_indent_fold() + new + call setline(1, ['', 'a', ' b', ' c']) + setl fen fdm=indent + 2 + norm! >> + let a=map(range(1,4), 'foldclosed(v:val)') + call assert_equal([-1,-1,-1,-1], a) +endfunc + +func! Test_indent_fold() + new + call setline(1, ['', 'a', ' b', ' c']) + setl fen fdm=indent + 2 + norm! >> + let a=map(range(1,4), 'foldclosed(v:val)') + call assert_equal([-1,-1,-1,-1], a) + bw! +endfunc + +func! Test_indent_fold2() + new + call setline(1, ['', '{{{', '}}}', '{{{', '}}}']) + setl fen fdm=marker + 2 + norm! >> + let a=map(range(1,5), 'foldclosed(v:val)') + call assert_equal([-1,-1,-1,4,4], a) + bw! +endfunc + +func Test_manual_fold_with_filter() + if !executable('cat') + return + endif + new + call setline(1, range(1, 20)) + 4,$fold + %foldopen + 10,$fold + %foldopen + " This filter command should not have an effect + 1,8! cat + call feedkeys('5ggzdzMGdd', 'xt') + call assert_equal(['1', '2', '3', '4', '5', '6', '7', '8', '9'], getline(1, '$')) + bwipe! +endfunc -- cgit From 689e0daa95fc870e49f3eb2f23cd6a76c392ff7d Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 2 Mar 2017 00:09:12 +0100 Subject: vim-patch:8.0.0136 Problem: When using indent folding and changing indent the wrong fold is opened. (Jonathan Fudger) Solution: Open the fold under the cursor a bit later. (Christian Brabandt) https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f --- src/nvim/ops.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/nvim') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 8bfda3c193..530193bd41 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -210,8 +210,6 @@ void op_shift(oparg_T *oap, int curs_top, int amount) } changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L); - /* The cursor line is not in a closed fold */ - foldOpenCursor(); if (oap->motion_type == kMTBlockWise) { curwin->w_cursor.lnum = oap->start.lnum; @@ -222,6 +220,9 @@ void op_shift(oparg_T *oap, int curs_top, int amount) } else --curwin->w_cursor.lnum; /* put cursor on last line, for ":>" */ + // The cursor line is not in a closed fold + foldOpenCursor(); + if (oap->line_count > p_report) { if (oap->op_type == OP_RSHIFT) s = (char_u *)">"; -- cgit From b1731fe1b5d7a9b89acb6c2292b1e3e8f9f33544 Mon Sep 17 00:00:00 2001 From: Matthew Malcomson Date: Tue, 28 Feb 2017 15:19:45 +0000 Subject: vim-patch:8.0.0388 Fix a problem when filtering manually folded lines When foldMarkAdjustRecurse() is called to adjust folds that start inside the range of lines that are being moved and end outside that range, it calculates `amount_after` for its recursive call incorrectly. The calculation assumes that folds inside the changed range are being deleted, but this is not always the case. This means nested folds that start after the changed range of lines are shifted an incorrect amount. We fix this by calculating the `amount_after` differently if the folds inside the changed range are not being deleted. --- src/nvim/ex_docmd.c | 4 ++-- src/nvim/fold.c | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'src/nvim') diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index ff0df9e51c..87b6959101 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -3654,10 +3654,10 @@ static linenr_T get_address(exarg_T *eap, n = 1; else n = getdigits(&cmd); - if (addr_type == ADDR_LOADED_BUFFERS || addr_type == ADDR_BUFFERS) + if (addr_type == ADDR_LOADED_BUFFERS || addr_type == ADDR_BUFFERS) { lnum = compute_buffer_local_count( addr_type, lnum, (i == '-') ? -1 * n : n); - else { + } else { // Relative line addressing, need to adjust for folded lines // now, but only do it after the first address. if (addr_type == ADDR_LINES && (i == '-' || i == '+') diff --git a/src/nvim/fold.c b/src/nvim/fold.c index d964da371a..1423463800 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -1438,13 +1438,16 @@ static void foldMarkAdjustRecurse(garray_T *gap, linenr_T line1, linenr_T line2, } else { /* 5. fold is below line1 and contains line2; need to * correct nested folds too */ - foldMarkAdjustRecurse(&fp->fd_nested, line1 - fp->fd_top, - line2 - fp->fd_top, amount, - amount_after + (fp->fd_top - top)); if (amount == MAXLNUM) { + foldMarkAdjustRecurse(&fp->fd_nested, line1 - fp->fd_top, + line2 - fp->fd_top, amount, + amount_after + (fp->fd_top - top)); fp->fd_len -= line2 - fp->fd_top + 1; fp->fd_top = line1; } else { + foldMarkAdjustRecurse(&fp->fd_nested, line1 - fp->fd_top, + line2 - fp->fd_top, amount, + amount_after - amount); fp->fd_len += amount_after - amount; fp->fd_top += amount; } -- cgit