aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/quickfix.c2
-rw-r--r--test/old/testdir/test_winfixbuf.vim19
2 files changed, 20 insertions, 1 deletions
diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c
index a88b781f32..3dd4e35f65 100644
--- a/src/nvim/quickfix.c
+++ b/src/nvim/quickfix.c
@@ -2699,7 +2699,7 @@ static void qf_goto_win_with_qfl_file(int qf_fnum)
// Didn't find it, go to the window before the quickfix
// window, unless 'switchbuf' contains 'uselast': in this case we
// try to jump to the previously used window first.
- if ((swb_flags & SWB_USELAST) && !prevwin->w_p_wfb && win_valid(prevwin)) {
+ if ((swb_flags & SWB_USELAST) && win_valid(prevwin) && !prevwin->w_p_wfb) {
win = prevwin;
} else if (altwin != NULL) {
win = altwin;
diff --git a/test/old/testdir/test_winfixbuf.vim b/test/old/testdir/test_winfixbuf.vim
index 2948be7859..5412fecd07 100644
--- a/test/old/testdir/test_winfixbuf.vim
+++ b/test/old/testdir/test_winfixbuf.vim
@@ -1576,6 +1576,7 @@ endfunc
" Fail vim.cmd if we try to change buffers while 'winfixbuf' is set
func Test_lua_command()
+ " CheckFeature lua
call s:reset_all_buffers()
enew
@@ -3129,3 +3130,21 @@ func Test_wprevious()
call delete("middle")
call delete("last")
endfunc
+
+func Test_quickfix_switchbuf_invalid_prevwin()
+ call s:reset_all_buffers()
+
+ let [l:first, _] = s:make_simple_quickfix()
+ call assert_notequal(l:first, bufnr())
+ call assert_equal(1, winnr('$'))
+
+ set switchbuf=uselast
+ split
+ copen
+ execute winnr('#') 'quit'
+
+ call assert_fails('cfirst', 'E1513:')
+ set switchbuf&
+endfunc
+
+" vim: shiftwidth=2 sts=2 expandtab