commit 1c52e90cd57c0ae3a289701fb658061a511a6756
parent 63a7b92e5885927a6b2ef11ede3d951e9ab38178
Author: phanium <91544758+phanen@users.noreply.github.com>
Date: Sun, 29 Jun 2025 22:44:17 +0800
fix(help): :help can focus unfocusable/hide window #34442
Problem:
:help/:helpgrep/:lhelpgrep can focus unfocusable/hide window
Solution:
Ignore unfocusable/hidden window when reusing help buffer.
Diffstat:
3 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/src/nvim/help.c b/src/nvim/help.c
@@ -141,7 +141,7 @@ void ex_help(exarg_T *eap)
} else {
wp = NULL;
FOR_ALL_WINDOWS_IN_TAB(wp2, curtab) {
- if (bt_help(wp2->w_buffer)) {
+ if (bt_help(wp2->w_buffer) && !wp2->w_config.hide && wp2->w_config.focusable) {
wp = wp2;
break;
}
diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c
@@ -2671,7 +2671,7 @@ static win_T *qf_find_help_win(void)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
{
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
- if (bt_help(wp->w_buffer)) {
+ if (bt_help(wp->w_buffer) && !wp->w_config.hide && wp->w_config.focusable) {
return wp;
}
}
diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua
@@ -6225,6 +6225,27 @@ describe('float window', function()
test_float_mouse_no_focus()
end)
+ it(':help (focusable=false, hide=true)', function()
+ n.add_builddir_to_rtp()
+ local w = curwin()
+ for _, helpcmd in ipairs({
+ 'help',
+ 'helpgrep api-types',
+ 'lhelpgrep api-types',
+ }) do
+ command(helpcmd)
+ local badwins = {
+ api.nvim_open_win(0, false, { focusable = false, relative = 'editor', width = 1, height = 1, row = 0, col = 0 }),
+ api.nvim_open_win(0, false, { hide = true, relative = 'editor', width = 1, height = 1, row = 0, col = 0 }),
+ }
+ command('helpclose')
+ command(helpcmd)
+ eq(false, tbl_contains(badwins, curwin()))
+ command('helpclose')
+ eq(w, curwin())
+ end
+ end)
+
it('j', function()
feed('<c-w>ji') -- INSERT to trigger screen change
if multigrid then