Skip to content

Commit

Permalink
fix(float): skip non-focusable windows for :windo (neovim#15378)
Browse files Browse the repository at this point in the history
  • Loading branch information
dstein64 committed Nov 11, 2021
1 parent 9d6a475 commit e8631cb
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/nvim/ex_cmds2.c
Expand Up @@ -1381,6 +1381,7 @@ void ex_listdo(exarg_T *eap)
listcmd_busy = true; // avoids setting pcmark below

while (!got_int && buf != NULL) {
bool execute = true;
if (eap->cmdidx == CMD_argdo) {
// go to argument "i"
if (i == ARGCOUNT) {
Expand All @@ -1406,11 +1407,14 @@ void ex_listdo(exarg_T *eap)
break;
}
assert(wp);
win_goto(wp);
if (curwin != wp) {
break; // something must be wrong
execute = !wp->w_floating || wp->w_float_config.focusable;
if (execute) {
win_goto(wp);
if (curwin != wp) {
break; // something must be wrong
}
}
wp = curwin->w_next;
wp = wp->w_next;
} else if (eap->cmdidx == CMD_tabdo) {
// go to window "tp"
if (!valid_tabpage(tp)) {
Expand All @@ -1433,8 +1437,10 @@ void ex_listdo(exarg_T *eap)

i++;
// execute the command
do_cmdline(eap->arg, eap->getline, eap->cookie,
DOCMD_VERBOSE + DOCMD_NOWAIT);
if (execute) {
do_cmdline(eap->arg, eap->getline, eap->cookie,
DOCMD_VERBOSE + DOCMD_NOWAIT);
}

if (eap->cmdidx == CMD_bufdo) {
// Done?
Expand Down Expand Up @@ -1485,7 +1491,7 @@ void ex_listdo(exarg_T *eap)
}
}

if (eap->cmdidx == CMD_windo) {
if (eap->cmdidx == CMD_windo && execute) {
validate_cursor(); // cursor may have moved
// required when 'scrollbind' has been set
if (curwin->w_p_scb) {
Expand Down
122 changes: 122 additions & 0 deletions test/functional/ui/float_spec.lua
@@ -1,18 +1,21 @@
local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
local global_helpers = require('test.helpers')
local os = require('os')
local clear, feed = helpers.clear, helpers.feed
local assert_alive = helpers.assert_alive
local command, feed_command = helpers.command, helpers.feed_command
local eval = helpers.eval
local eq = helpers.eq
local neq = helpers.neq
local exec_lua = helpers.exec_lua
local insert = helpers.insert
local meths = helpers.meths
local curbufmeths = helpers.curbufmeths
local funcs = helpers.funcs
local run = helpers.run
local pcall_err = helpers.pcall_err
local tbl_contains = global_helpers.tbl_contains

describe('float window', function()
before_each(function()
Expand Down Expand Up @@ -294,6 +297,125 @@ describe('float window', function()
eq(12, pos[2])
end)

it('is not operated on by windo when non-focusable #15374', function()
command([[
let winids = []
windo call add(winids, win_getid())
]])
local windo_count_before = eval('len(winids)')
local winid = exec_lua([[
local bufnr = vim.api.nvim_create_buf(false, true)
local opts = {
relative = 'editor',
focusable = false,
height = 5,
width = 5,
col = 5,
row = 5,
}
return vim.api.nvim_open_win(bufnr, false, opts)
]])
command([[
let winids = []
windo call add(winids, win_getid())
]])
local windo_count_after = eval('len(winids)')
eq(windo_count_before, windo_count_after)
eq(false, tbl_contains(eval('winids'), winid))
end)

it('is operated on by windo when focusable', function()
command([[
let winids = []
windo call add(winids, win_getid())
]])
local windo_count_before = eval('len(winids)')
local winid = exec_lua([[
local bufnr = vim.api.nvim_create_buf(false, true)
local opts = {
relative = 'editor',
focusable = true,
height = 5,
width = 5,
col = 5,
row = 5,
}
return vim.api.nvim_open_win(bufnr, false, opts)
]])
command([[
let winids = []
windo call add(winids, win_getid())
]])
local windo_count_after = eval('len(winids)')
eq(windo_count_before + 1, windo_count_after)
eq(true, tbl_contains(eval('winids'), winid))
end)

it('is not active after windo when non-focusable #15374', function()
local winid = exec_lua([[
local bufnr = vim.api.nvim_create_buf(false, true)
local opts = {
relative = 'editor',
focusable = false,
height = 5,
width = 5,
col = 5,
row = 5,
}
return vim.api.nvim_open_win(bufnr, false, opts)
]])
command('windo echo')
neq(eval('win_getid()'), winid)
end)

it('is active after windo when focusable', function()
local winid = exec_lua([[
local bufnr = vim.api.nvim_create_buf(false, true)
local opts = {
relative = 'editor',
focusable = true,
height = 5,
width = 5,
col = 5,
row = 5,
}
return vim.api.nvim_open_win(bufnr, false, opts)
]])
command('windo echo')
eq(eval('win_getid()'), winid)
end)

it('supports windo with focusable and non-focusable floats', function()
local winids = exec_lua([[
local result = {vim.api.nvim_get_current_win()}
local bufnr = vim.api.nvim_create_buf(false, true)
local opts = {
relative = 'editor',
focusable = false,
height = 5,
width = 5,
col = 5,
row = 5,
}
vim.api.nvim_open_win(bufnr, false, opts)
opts.focusable = true
table.insert(result, vim.api.nvim_open_win(bufnr, false, opts))
opts.focusable = false
vim.api.nvim_open_win(bufnr, false, opts)
opts.focusable = true
table.insert(result, vim.api.nvim_open_win(bufnr, false, opts))
opts.focusable = false
vim.api.nvim_open_win(bufnr, false, opts)
return result
]])
table.sort(winids)
command([[
let winids = []
windo call add(winids, win_getid())
call sort(winids)
]])
eq(winids, eval('winids'))
end)

local function with_ext_multigrid(multigrid)
local screen
Expand Down

0 comments on commit e8631cb

Please sign in to comment.