diff options
| author | Justin M. Keyes <justinkz@gmail.com> | 2017-03-02 00:00:51 +0100 | 
|---|---|---|
| committer | Justin M. Keyes <justinkz@gmail.com> | 2017-03-02 00:08:51 +0100 | 
| commit | 3c740f7424f232792609320b2093bbbd899ab11b (patch) | |
| tree | 899324be60215c17638a97cc625e2f1fdaef8a18 /src | |
| parent | 985bc6c6e055785e9cee22c1fd70127f82cdbffb (diff) | |
| download | rneovim-3c740f7424f232792609320b2093bbbd899ab11b.tar.gz rneovim-3c740f7424f232792609320b2093bbbd899ab11b.tar.bz2 rneovim-3c740f7424f232792609320b2093bbbd899ab11b.zip | |
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
Diffstat (limited to 'src')
| -rw-r--r-- | src/nvim/ex_docmd.c | 28 | ||||
| -rw-r--r-- | src/nvim/testdir/test_fold.vim | 114 | 
2 files changed, 133 insertions, 9 deletions
| 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 | 
