vim-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)
0a08c63da1
This commit is contained in:
Jan Edmund Lazo
2019-06-11 23:16:16 -04:00
parent 005316ae41
commit 22d58ab664
4 changed files with 55 additions and 14 deletions

View File

@@ -5227,12 +5227,8 @@ static void nv_down(cmdarg_T *cap)
cap->arg = FORWARD; cap->arg = FORWARD;
nv_page(cap); nv_page(cap);
} else if (bt_quickfix(curbuf) && cap->cmdchar == CAR) { } else if (bt_quickfix(curbuf) && cap->cmdchar == CAR) {
// In a quickfix window a <CR> jumps to the error under the cursor. // Quickfix window only: view the result under the cursor.
if (curwin->w_llist_ref == NULL) { qf_view_result(false);
do_cmdline_cmd(".cc"); // quickfix window
} else {
do_cmdline_cmd(".ll"); // location list window
}
} else { } else {
// In the cmdline window a <CR> executes the command. // In the cmdline window a <CR> executes the command.
if (cmdwin_type != 0 && cap->cmdchar == CAR) { if (cmdwin_type != 0 && cap->cmdchar == CAR) {

View File

@@ -2845,6 +2845,39 @@ static char_u *qf_types(int c, int nr)
return buf; return buf;
} }
// 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(bool 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 cmd[32];
snprintf(cmd, sizeof(cmd), "split +%" PRId64 "%s",
(int64_t)curwin->w_cursor.lnum,
IS_LL_WINDOW(curwin) ? "ll" : "cc");
if (do_cmdline_cmd(cmd) == OK) {
do_cmdline_cmd("clearjumps");
}
return;
}
do_cmdline_cmd((IS_LL_WINDOW(curwin) ? ".ll" : ".cc"));
}
/* /*
* ":cwindow": open the quickfix window if we have errors to display, * ":cwindow": open the quickfix window if we have errors to display,
* close it if not. * close it if not.

View File

@@ -3372,3 +3372,21 @@ func Test_lbuffer_with_bwipe()
au! au!
augroup END augroup END
endfunc 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

View File

@@ -443,17 +443,11 @@ wingotofile:
curwin->w_set_curswant = TRUE; curwin->w_set_curswant = TRUE;
break; break;
// Quickfix window only: view the result under the cursor in a new split.
case K_KENTER: case K_KENTER:
case CAR: case CAR:
/*
* In a quickfix window a <CR> jumps to the error under the
* cursor in a new window.
*/
if (bt_quickfix(curbuf)) { if (bt_quickfix(curbuf)) {
sprintf(cbuf, "split +%" PRId64 "%s", qf_view_result(true);
(int64_t)curwin->w_cursor.lnum,
(curwin->w_llist_ref == NULL) ? "cc" : "ll");
do_cmdline_cmd(cbuf);
} }
break; break;