Skip to content

Commit 0a08c63

Browse files
committed
patch 8.1.0213: CTRL-W CR does not work properly in a quickfix window
Problem: CTRL-W CR does not work properly in a quickfix window. Solution: Split the window if needed. (Jason Franklin)
1 parent 5390144 commit 0a08c63

6 files changed

Lines changed: 65 additions & 23 deletions

File tree

src/normal.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6202,18 +6202,12 @@ nv_down(cmdarg_T *cap)
62026202
cap->arg = FORWARD;
62036203
nv_page(cap);
62046204
}
6205-
else
62066205
#if defined(FEAT_QUICKFIX)
6207-
/* In a quickfix window a <CR> jumps to the error under the cursor. */
6208-
if (bt_quickfix(curbuf) && cap->cmdchar == CAR)
6209-
{
6210-
if (curwin->w_llist_ref == NULL)
6211-
do_cmdline_cmd((char_u *)".cc"); /* quickfix window */
6212-
else
6213-
do_cmdline_cmd((char_u *)".ll"); /* location list window */
6214-
}
6215-
else
6206+
/* Quickfix window only: view the result under the cursor. */
6207+
else if (bt_quickfix(curbuf) && cap->cmdchar == CAR)
6208+
qf_view_result(FALSE);
62166209
#endif
6210+
else
62176211
{
62186212
#ifdef FEAT_CMDWIN
62196213
/* In the cmdline window a <CR> executes the command. */

src/proto/quickfix.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ void qf_list(exarg_T *eap);
77
void qf_age(exarg_T *eap);
88
void qf_history(exarg_T *eap);
99
void qf_mark_adjust(win_T *wp, linenr_T line1, linenr_T line2, long amount, long amount_after);
10+
void qf_view_result(int split);
1011
void ex_cwindow(exarg_T *eap);
1112
void ex_cclose(exarg_T *eap);
1213
void ex_copen(exarg_T *eap);

src/quickfix.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3489,6 +3489,42 @@ qf_types(int c, int nr)
34893489
return buf;
34903490
}
34913491

3492+
/*
3493+
* When "split" is FALSE: Open the entry/result under the cursor.
3494+
* When "split" is TRUE: Open the entry/result under the cursor in a new window.
3495+
*/
3496+
void
3497+
qf_view_result(int split)
3498+
{
3499+
qf_info_T *qi = &ql_info;
3500+
3501+
if (!bt_quickfix(curbuf))
3502+
return;
3503+
3504+
if (IS_LL_WINDOW(curwin))
3505+
qi = GET_LOC_LIST(curwin);
3506+
3507+
if (qi == NULL || qi->qf_lists[qi->qf_curlist].qf_count == 0)
3508+
{
3509+
EMSG(_(e_quickfix));
3510+
return;
3511+
}
3512+
3513+
if (split)
3514+
{
3515+
char_u cmd[32];
3516+
3517+
vim_snprintf((char *)cmd, sizeof(cmd), "split +%ld%s",
3518+
(long)curwin->w_cursor.lnum,
3519+
IS_LL_WINDOW(curwin) ? "ll" : "cc");
3520+
if (do_cmdline_cmd(cmd) == OK)
3521+
do_cmdline_cmd((char_u *) "clearjumps");
3522+
return;
3523+
}
3524+
3525+
do_cmdline_cmd((char_u *)(IS_LL_WINDOW(curwin) ? ".ll" : ".cc"));
3526+
}
3527+
34923528
/*
34933529
* ":cwindow": open the quickfix window if we have errors to display,
34943530
* close it if not.

src/testdir/test_quickfix.vim

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3504,3 +3504,21 @@ func Test_filter_clist()
35043504
call assert_equal([' 1 abc:pat1: '],
35053505
\ split(execute('filter /pat1/ clist'), "\n"))
35063506
endfunc
3507+
3508+
" Tests for the "CTRL-W <CR>" command.
3509+
func Xview_result_split_tests(cchar)
3510+
call s:setup_commands(a:cchar)
3511+
3512+
" Test that "CTRL-W <CR>" in a qf/ll window fails with empty list.
3513+
call g:Xsetlist([])
3514+
Xopen
3515+
let l:win_count = winnr('$')
3516+
call assert_fails('execute "normal! \<C-W>\<CR>"', 'E42')
3517+
call assert_equal(l:win_count, winnr('$'))
3518+
Xclose
3519+
endfunc
3520+
3521+
func Test_view_result_split()
3522+
call Xview_result_split_tests('c')
3523+
call Xview_result_split_tests('l')
3524+
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,8 @@ static char *(features[]) =
793793

794794
static int included_patches[] =
795795
{ /* Add new patch number below this line */
796+
/**/
797+
213,
796798
/**/
797799
212,
798800
/**/

src/window.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -520,23 +520,14 @@ do_window(
520520
break;
521521
#endif
522522

523+
/* Quickfix window only: view the result under the cursor in a new split. */
524+
#if defined(FEAT_QUICKFIX)
523525
case K_KENTER:
524526
case CAR:
525-
#if defined(FEAT_QUICKFIX)
526-
/*
527-
* In a quickfix window a <CR> jumps to the error under the
528-
* cursor in a new window.
529-
*/
530527
if (bt_quickfix(curbuf))
531-
{
532-
sprintf((char *)cbuf, "split +%ld%s",
533-
(long)curwin->w_cursor.lnum,
534-
(curwin->w_llist_ref == NULL) ? "cc" : "ll");
535-
do_cmdline_cmd(cbuf);
536-
}
537-
#endif
528+
qf_view_result(TRUE);
538529
break;
539-
530+
#endif
540531

541532
/* CTRL-W g extended commands */
542533
case 'g':

0 commit comments

Comments
 (0)