Skip to content

Commit

Permalink
fix: window options
Browse files Browse the repository at this point in the history
  • Loading branch information
olimorris committed Mar 18, 2024
1 parent 0949275 commit 145d04c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lua/codecompanion/strategies/chat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ local function watch_cursor()
end

_G.codecompanion_chats = {}
_G.codecompanion_win_opts = {}

local registered_cmp = false

Expand Down Expand Up @@ -262,6 +263,21 @@ local function chat_autocmds(bufnr)
end,
})

api.nvim_create_autocmd("BufEnter", {
group = aug,
buffer = bufnr,
callback = function()
ui.set_win_options(api.nvim_get_current_win(), config.options.display.chat.win_options)
end,
})
api.nvim_create_autocmd("BufLeave", {
group = aug,
buffer = bufnr,
callback = function()
ui.set_win_options(api.nvim_get_current_win(), _G.codecompanion_win_opts)
end,
})

-- Clear the virtual text when the user starts typing
if utils.count(_G.codecompanion_chats) == 0 then
local insertenter_autocmd
Expand Down Expand Up @@ -400,6 +416,7 @@ function Chat.new(args)
api.nvim_set_current_buf(bufnr)
end

_G.codecompanion_win_opts = ui.get_win_options(winid, config.options.display.chat.win_options)
ui.set_win_options(winid, config.options.display.chat.win_options)
vim.cmd("setlocal formatoptions-=t")
ui.buf_scroll_to_end(bufnr)
Expand Down
11 changes: 11 additions & 0 deletions lua/codecompanion/utils/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,17 @@ function M.selector(items, opts)
end)
end

---@param winid number
---@param opts table
function M.get_win_options(winid, opts)
local options = {}
for k, _ in pairs(opts) do
options[k] = api.nvim_get_option_value(k, { scope = "local", win = winid })
end

return options
end

---@param winid number
---@param opts table
function M.set_win_options(winid, opts)
Expand Down

0 comments on commit 145d04c

Please sign in to comment.