fix(startup): respect enter for windows created in startup scripts #37287

Problem: When a split window is created from the init script using nvim_open_win()
with enter=false, the current window focus is not preserved. The cursor
incorrectly moves into the newly created split during startup.

Solution: Save curwin before the iteration loop in create_windows(), and
restore it after the loop. also update edit_buffers() to use curwin instead
of firstwin.
This commit is contained in:
glepnir
2026-07-13 00:30:40 +08:00
committed by GitHub
parent 17f13ab338
commit 58b6310adc
3 changed files with 59 additions and 8 deletions

View File

@@ -1,6 +1,7 @@
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')
local tt = require('test.functional.testterm')
local clear, curbuf, curbuf_contents, curwin, eq, neq, matches, ok, feed, insert, eval =
n.clear,
@@ -2303,6 +2304,51 @@ describe('API/win', function()
|
]])
end)
it('keep focus when creating split window with enter=false in init script', function()
local script_file = 'Xstartup.lua'
t.write_file(
script_file,
[[
vim.o.laststatus = 0
local enter = vim.g.test_enter
local win = vim.api.nvim_open_win(vim.api.nvim_create_buf(false, true), enter, {
split = 'left',
win = 0,
})
]]
)
finally(function()
os.remove(script_file)
end)
local screen = tt.setup_child_nvim({
'--clean',
'--cmd',
'let g:test_enter = v:false',
'-u',
script_file,
})
screen:expect([[
│^ |
~ │~ |*4
0,0-1 All |
{5:-- TERMINAL --} |
]])
screen:detach()
screen = tt.setup_child_nvim({
'--clean',
'--cmd',
'let g:test_enter = v:true',
'-u',
script_file,
})
screen:expect([[
^ │ |
~ │~ |*4
0,0-1 All |
{5:-- TERMINAL --} |
]])
end)
end)
describe('set_config', function()