Skip to content

Commit ff6f962

Browse files
deathbeamjellydn
andauthored
fix: Properly handle splits on neovim stable (#112)
Signed-off-by: Tomas Slusny <slusnucky@gmail.com> Co-authored-by: Dung Duc Huynh (Kaka) <870029+jellydn@users.noreply.github.com>
1 parent 28c154a commit ff6f962

1 file changed

Lines changed: 12 additions & 19 deletions

File tree

lua/CopilotChat/init.lua

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -329,35 +329,28 @@ function M.open(config, source, no_focus)
329329
win_opts.height = math.floor(vim.o.lines * config.window.height)
330330
elseif layout == 'vertical' then
331331
if is_stable() then
332-
win_opts.zindex = config.window.zindex
333-
win_opts.relative = 'editor'
334-
win_opts.width = math.floor(vim.o.columns * 0.5) -- 50% width
335-
win_opts.height = vim.o.lines -- full height
336-
win_opts.row = 0 -- top of the screen
337-
win_opts.col = math.floor(vim.o.columns * 0.5) -- right side of the screen
338-
win_opts.border = config.window.border
339-
win_opts.title = config.window.title
340-
win_opts.footer = config.window.footer
332+
vim.cmd('vsplit')
333+
state.window = vim.api.nvim_get_current_win()
334+
vim.api.nvim_win_set_buf(state.window, state.chat.bufnr)
335+
vim.api.nvim_set_current_win(state.source.winnr)
341336
else
342337
win_opts.vertical = true
343338
end
344339
elseif layout == 'horizontal' then
345340
if is_stable() then
346-
win_opts.zindex = config.window.zindex
347-
win_opts.relative = 'editor'
348-
win_opts.height = math.floor(vim.o.lines * 0.5) -- 50% height
349-
win_opts.width = vim.o.columns -- full width
350-
win_opts.row = math.floor(vim.o.lines * 0.5) -- bottom of the screen
351-
win_opts.col = 0 -- left side of the screen
352-
win_opts.border = config.window.border
353-
win_opts.title = config.window.title
354-
win_opts.footer = config.window.footer
341+
vim.cmd('split')
342+
state.window = vim.api.nvim_get_current_win()
343+
vim.api.nvim_win_set_buf(state.window, state.chat.bufnr)
344+
vim.api.nvim_set_current_win(state.source.winnr)
355345
else
356346
win_opts.vertical = false
357347
end
358348
end
359349

360-
state.window = vim.api.nvim_open_win(state.chat.bufnr, false, win_opts)
350+
if not state.window or not vim.api.nvim_win_is_valid(state.window) then
351+
state.window = vim.api.nvim_open_win(state.chat.bufnr, false, win_opts)
352+
end
353+
361354
vim.wo[state.window].wrap = true
362355
vim.wo[state.window].linebreak = true
363356
vim.wo[state.window].cursorline = true

0 commit comments

Comments
 (0)