diff options
author | Bram Moolenaar <Bram@vim.org> | 2018-07-25 22:36:52 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2018-07-25 22:36:52 +0200 |
commit | 0a08c63da17dfd93ac2885e3f3f8a083a9b3131c (patch) | |
tree | 9d557c0e8454c09c889e6ee033b178118bc9aa7e /src | |
parent | 53901442f37a59e5495165f91db5574c0b43ab04 (diff) | |
download | vim-git-0a08c63da17dfd93ac2885e3f3f8a083a9b3131c.tar.gz |
patch 8.1.0213: CTRL-W CR does not work properly in a quickfix windowv8.1.0213
Problem: CTRL-W CR does not work properly in a quickfix window.
Solution: Split the window if needed. (Jason Franklin)
Diffstat (limited to 'src')
-rw-r--r-- | src/normal.c | 14 | ||||
-rw-r--r-- | src/proto/quickfix.pro | 1 | ||||
-rw-r--r-- | src/quickfix.c | 36 | ||||
-rw-r--r-- | src/testdir/test_quickfix.vim | 18 | ||||
-rw-r--r-- | src/version.c | 2 | ||||
-rw-r--r-- | src/window.c | 17 |
6 files changed, 65 insertions, 23 deletions
diff --git a/src/normal.c b/src/normal.c index 4d51c3320..4e36d5607 100644 --- a/src/normal.c +++ b/src/normal.c @@ -6202,18 +6202,12 @@ nv_down(cmdarg_T *cap) cap->arg = FORWARD; nv_page(cap); } - else #if defined(FEAT_QUICKFIX) - /* In a quickfix window a <CR> jumps to the error under the cursor. */ - if (bt_quickfix(curbuf) && cap->cmdchar == CAR) - { - if (curwin->w_llist_ref == NULL) - do_cmdline_cmd((char_u *)".cc"); /* quickfix window */ - else - do_cmdline_cmd((char_u *)".ll"); /* location list window */ - } - else + /* Quickfix window only: view the result under the cursor. */ + else if (bt_quickfix(curbuf) && cap->cmdchar == CAR) + qf_view_result(FALSE); #endif + else { #ifdef FEAT_CMDWIN /* In the cmdline window a <CR> executes the command. */ diff --git a/src/proto/quickfix.pro b/src/proto/quickfix.pro index d32655f07..26a5de0bf 100644 --- a/src/proto/quickfix.pro +++ b/src/proto/quickfix.pro @@ -7,6 +7,7 @@ void qf_list(exarg_T *eap); void qf_age(exarg_T *eap); void qf_history(exarg_T *eap); void qf_mark_adjust(win_T *wp, linenr_T line1, linenr_T line2, long amount, long amount_after); +void qf_view_result(int split); void ex_cwindow(exarg_T *eap); void ex_cclose(exarg_T *eap); void ex_copen(exarg_T *eap); diff --git a/src/quickfix.c b/src/quickfix.c index f758980b4..aac1e3414 100644 --- a/src/quickfix.c +++ b/src/quickfix.c @@ -3490,6 +3490,42 @@ qf_types(int c, int nr) } /* + * When "split" is FALSE: Open the entry/result under the cursor. + * When "split" is TRUE: Open the entry/result under the cursor in a new window. + */ + void +qf_view_result(int split) +{ + qf_info_T *qi = &ql_info; + + if (!bt_quickfix(curbuf)) + return; + + if (IS_LL_WINDOW(curwin)) + qi = GET_LOC_LIST(curwin); + + if (qi == NULL || qi->qf_lists[qi->qf_curlist].qf_count == 0) + { + EMSG(_(e_quickfix)); + return; + } + + if (split) + { + char_u cmd[32]; + + vim_snprintf((char *)cmd, sizeof(cmd), "split +%ld%s", + (long)curwin->w_cursor.lnum, + IS_LL_WINDOW(curwin) ? "ll" : "cc"); + if (do_cmdline_cmd(cmd) == OK) + do_cmdline_cmd((char_u *) "clearjumps"); + return; + } + + do_cmdline_cmd((char_u *)(IS_LL_WINDOW(curwin) ? ".ll" : ".cc")); +} + +/* * ":cwindow": open the quickfix window if we have errors to display, * close it if not. * ":lwindow": open the location list window if we have locations to display, diff --git a/src/testdir/test_quickfix.vim b/src/testdir/test_quickfix.vim index c8f0984b0..d41815f3c 100644 --- a/src/testdir/test_quickfix.vim +++ b/src/testdir/test_quickfix.vim @@ -3504,3 +3504,21 @@ func Test_filter_clist() call assert_equal([' 1 abc:pat1: '], \ split(execute('filter /pat1/ clist'), "\n")) endfunc + +" Tests for the "CTRL-W <CR>" command. +func Xview_result_split_tests(cchar) + call s:setup_commands(a:cchar) + + " Test that "CTRL-W <CR>" in a qf/ll window fails with empty list. + call g:Xsetlist([]) + Xopen + let l:win_count = winnr('$') + call assert_fails('execute "normal! \<C-W>\<CR>"', 'E42') + call assert_equal(l:win_count, winnr('$')) + Xclose +endfunc + +func Test_view_result_split() + call Xview_result_split_tests('c') + call Xview_result_split_tests('l') +endfunc diff --git a/src/version.c b/src/version.c index 81ed54446..830de26fc 100644 --- a/src/version.c +++ b/src/version.c @@ -794,6 +794,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 213, +/**/ 212, /**/ 211, diff --git a/src/window.c b/src/window.c index f059b3766..e1781d3f4 100644 --- a/src/window.c +++ b/src/window.c @@ -520,23 +520,14 @@ wingotofile: break; #endif +/* Quickfix window only: view the result under the cursor in a new split. */ +#if defined(FEAT_QUICKFIX) case K_KENTER: case CAR: -#if defined(FEAT_QUICKFIX) - /* - * In a quickfix window a <CR> jumps to the error under the - * cursor in a new window. - */ if (bt_quickfix(curbuf)) - { - sprintf((char *)cbuf, "split +%ld%s", - (long)curwin->w_cursor.lnum, - (curwin->w_llist_ref == NULL) ? "cc" : "ll"); - do_cmdline_cmd(cbuf); - } -#endif + qf_view_result(TRUE); break; - +#endif /* CTRL-W g extended commands */ case 'g': |