Skip to content

Commit

Permalink
feat: add support for more layout options for chat window (CopilotC-N…
Browse files Browse the repository at this point in the history
…vim#89)

This for example allows window right below cursor in style of vscode inline popup
  • Loading branch information
deathbeam authored Feb 28, 2024
1 parent 62599ab commit c3fc60b
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions lua/CopilotChat/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ local function show_help()
local out = 'Press '
for name, key in pairs(M.config.mappings) do
if key then
out = out .. "'" .. key .. "' to " .. name .. ', \n'
out = out .. "'" .. key .. "' to " .. name .. ', '
end
end

Expand Down Expand Up @@ -248,13 +248,15 @@ function M.open(config)
elseif layout == 'horizontal' then
win_opts.vertical = false
elseif layout == 'float' then
win_opts.relative = 'editor'
win_opts.relative = config.window.relative
win_opts.border = config.window.border
win_opts.title = config.window.title
win_opts.row = math.floor(vim.o.lines * 0.2)
win_opts.col = math.floor(vim.o.columns * 0.1)
win_opts.width = math.floor(vim.o.columns * 0.8)
win_opts.height = math.floor(vim.o.lines * 0.6)
win_opts.footer = config.window.footer
win_opts.row = config.window.row or math.floor(vim.o.lines * ((1 - config.window.height) / 2))
win_opts.col = config.window.col
or math.floor(vim.o.columns * ((1 - config.window.width) / 2))
win_opts.width = math.floor(vim.o.columns * config.window.width)
win_opts.height = math.floor(vim.o.lines * config.window.height)
end

state.window = vim.api.nvim_open_win(state.chat.bufnr, false, win_opts)
Expand Down Expand Up @@ -385,11 +387,16 @@ M.config = {
return select.visual() or select.line()
end,
window = {
layout = 'vertical',
width = 0.8,
height = 0.6,
border = 'single',
layout = 'vertical', -- 'vertical', 'horizontal', 'float'
-- Options for float layout
relative = 'editor', -- 'editor', 'win', 'cursor', 'mouse'
border = 'single', -- 'none', single', 'double', 'rounded', 'solid', 'shadow'
width = 0.8, -- fractional width of parent
height = 0.6, -- fractional height of parent
row = nil, -- row position of the window, default is centered
col = nil, -- column position of the window, default is centered
title = 'Copilot Chat',
footer = nil,
},
mappings = {
close = 'q',
Expand Down

0 comments on commit c3fc60b

Please sign in to comment.