From 22d58ab66459c4c38f7117902b9498f81b4edfe5 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Tue, 11 Jun 2019 23:16:16 -0400 Subject: 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) https://github.com/vim/vim/commit/0a08c63da17dfd93ac2885e3f3f8a083a9b3131c --- src/nvim/normal.c | 8 ++------ src/nvim/quickfix.c | 33 +++++++++++++++++++++++++++++++++ src/nvim/testdir/test_quickfix.vim | 18 ++++++++++++++++++ src/nvim/window.c | 10 ++-------- 4 files changed, 55 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 0a4d32d438..f99e42e2e4 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -5227,12 +5227,8 @@ static void nv_down(cmdarg_T *cap) cap->arg = FORWARD; nv_page(cap); } else if (bt_quickfix(curbuf) && cap->cmdchar == CAR) { - // In a quickfix window a jumps to the error under the cursor. - if (curwin->w_llist_ref == NULL) { - do_cmdline_cmd(".cc"); // quickfix window - } else { - do_cmdline_cmd(".ll"); // location list window - } + // Quickfix window only: view the result under the cursor. + qf_view_result(false); } else { // In the cmdline window a executes the command. if (cmdwin_type != 0 && cap->cmdchar == CAR) { diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index ced0cf0f80..3c945a505b 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -2845,6 +2845,39 @@ static char_u *qf_types(int c, int nr) 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, * close it if not. diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim index 16fb86ea08..fcb02d3437 100644 --- a/src/nvim/testdir/test_quickfix.vim +++ b/src/nvim/testdir/test_quickfix.vim @@ -3372,3 +3372,21 @@ func Test_lbuffer_with_bwipe() au! augroup END endfunc + +" Tests for the "CTRL-W " command. +func Xview_result_split_tests(cchar) + call s:setup_commands(a:cchar) + + " Test that "CTRL-W " in a qf/ll window fails with empty list. + call g:Xsetlist([]) + Xopen + let l:win_count = winnr('$') + call assert_fails('execute "normal! \\"', '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/nvim/window.c b/src/nvim/window.c index e6b19cf88d..1cf5d7fd92 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -443,17 +443,11 @@ wingotofile: curwin->w_set_curswant = TRUE; break; + // Quickfix window only: view the result under the cursor in a new split. case K_KENTER: case CAR: - /* - * In a quickfix window a jumps to the error under the - * cursor in a new window. - */ if (bt_quickfix(curbuf)) { - sprintf(cbuf, "split +%" PRId64 "%s", - (int64_t)curwin->w_cursor.lnum, - (curwin->w_llist_ref == NULL) ? "cc" : "ll"); - do_cmdline_cmd(cbuf); + qf_view_result(true); } break; -- cgit