diff options
-rw-r--r-- | src/nvim/window.c | 2 | ||||
-rw-r--r-- | test/functional/ex_cmds/help_spec.lua | 27 |
2 files changed, 28 insertions, 1 deletions
diff --git a/src/nvim/window.c b/src/nvim/window.c index e60cfbfb92..f9a0839702 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -6062,7 +6062,7 @@ static win_T *get_snapshot_focus(int idx) } } - return sn->fr_win; + return win_valid(sn->fr_win) ? sn->fr_win : NULL; } /* diff --git a/test/functional/ex_cmds/help_spec.lua b/test/functional/ex_cmds/help_spec.lua new file mode 100644 index 0000000000..66d7d7d89f --- /dev/null +++ b/test/functional/ex_cmds/help_spec.lua @@ -0,0 +1,27 @@ +local helpers = require('test.functional.helpers')(after_each) + +local clear = helpers.clear +local command = helpers.command +local eq = helpers.eq +local funcs = helpers.funcs + +describe(':help', function() + before_each(clear) + + it('window closed makes cursor return to a valid win/buf #9773', function() + command('help help') + eq(1001, funcs.win_getid()) + command('quit') + eq(1000, funcs.win_getid()) + + command('autocmd WinNew * wincmd p') + + command('help help') + -- Window 1002 is opened, but the autocmd switches back to 1000 and + -- creates the help buffer there instead. + eq(1000, funcs.win_getid()) + command('quit') + -- Before #9773, Nvim would crash on quitting the help window. + eq(1002, funcs.win_getid()) + end) +end) |