Skip to content

Commit b89b557

Browse files
authored
fix: do not reroute to invalid (deleted) window (#423)
## 📃 Summary closes #415 we assume the window list is valid, but in case of `bd`, it actually deletes the window, which then makes the plugin fallback to a new set of window we should make sure the window is valid before actually rerouting
1 parent 50e3baa commit b89b557

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

.github/workflows/main.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
uses: rhysd/action-setup-vim@v1
3939
with:
4040
neovim: true
41-
version: v0.10.1
41+
version: v0.10.2
4242

4343
- name: generate documentation
4444
run: make documentation-ci
@@ -54,7 +54,7 @@ jobs:
5454
timeout-minutes: 1
5555
strategy:
5656
matrix:
57-
neovim_version: ['v0.9.5', 'v0.10.1']
57+
neovim_version: ['v0.9.5', 'v0.10.2']
5858

5959
steps:
6060
- uses: actions/checkout@v4

lua/no-neck-pain/main.lua

+8-2
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,6 @@ function main.enable(scope)
262262

263263
vim.cmd("rightbelow vertical split")
264264

265-
vim.print(opened_buffers)
266-
267265
if vim.tbl_count(opened_buffers) > 0 then
268266
local bufname, _ = next(opened_buffers)
269267
if vim.startswith(bufname, "NoNamePain") then
@@ -392,6 +390,14 @@ function main.enable(scope)
392390

393391
local new_focus = wins[idx] or state.get_previously_focused_win(state)
394392

393+
if not vim.api.nvim_win_is_valid(new_focus) then
394+
return log.debug(
395+
p.event,
396+
"aborting reroute, %d is not a valid window",
397+
new_focus
398+
)
399+
end
400+
395401
vim.api.nvim_set_current_win(new_focus)
396402

397403
return log.debug(p.event, "rerouted focus of %d to %d", current_side, new_focus)

tests/test_autocmds.lua

+26
Original file line numberDiff line numberDiff line change
@@ -242,4 +242,30 @@ T["skipEnteringNoNeckPainBuffer"]["one side only + full width split doesn't brin
242242
Helpers.expect.equality(child.api.nvim_get_current_win(), 1000)
243243
end
244244

245+
T["skipEnteringNoNeckPainBuffer"]["does not reroute to invalid windows"] = function()
246+
child.lua(
247+
[[ require('no-neck-pain').setup({width=50, autocmds = { skipEnteringNoNeckPainBuffer = true }}) ]]
248+
)
249+
child.nnp()
250+
251+
child.cmd("e foo")
252+
child.wait()
253+
child.cmd("e bar")
254+
child.wait()
255+
256+
Helpers.expect.equality(child.get_wins_in_tab(), { 1001, 1000, 1002 })
257+
Helpers.expect.equality(child.api.nvim_get_current_win(), 1000)
258+
259+
child.cmd("bd")
260+
child.wait()
261+
262+
if child.fn.has("nvim-0.10") == 0 then
263+
Helpers.expect.equality(child.get_wins_in_tab(), { 1004, 1003, 1005 })
264+
Helpers.expect.equality(child.api.nvim_get_current_win(), 1003)
265+
else
266+
Helpers.expect.equality(child.get_wins_in_tab(), { 1005, 1004, 1006 })
267+
Helpers.expect.equality(child.api.nvim_get_current_win(), 1004)
268+
end
269+
end
270+
245271
return T

0 commit comments

Comments
 (0)