Skip to content

Commit

Permalink
fix: Properly check if window layout changed before resetting (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
deathbeam authored Mar 31, 2024
1 parent 6225735 commit 51ec2b4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lua/CopilotChat/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ local context = require('CopilotChat.context')
local prompts = require('CopilotChat.prompts')
local debuginfo = require('CopilotChat.debuginfo')
local tiktoken = require('CopilotChat.tiktoken')
local utils = require('CopilotChat.utils')

local M = {}
local plugin_name = 'CopilotChat.nvim'
Expand Down Expand Up @@ -274,8 +275,8 @@ end
---@param config CopilotChat.config|CopilotChat.config.prompt|nil
---@param source CopilotChat.config.source?
function M.open(config, source, no_insert)
local should_reset = config and config.window ~= nil and not vim.tbl_isempty(config.window)
config = vim.tbl_deep_extend('force', M.config, config or {})
local should_reset = state.config and not utils.table_equals(config.window, state.config.window)
state.config = config
state.source = vim.tbl_extend('keep', source or {}, {
bufnr = vim.api.nvim_get_current_buf(),
Expand Down
24 changes: 24 additions & 0 deletions lua/CopilotChat/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,28 @@ function M.temp_file(text)
return temp_file
end

--- Check if a table is equal to another table
---@param a table The first table
---@param b table The second table
---@return boolean
function M.table_equals(a, b)
if type(a) ~= type(b) then
return false
end
if type(a) ~= 'table' then
return a == b
end
for k, v in pairs(a) do
if not M.table_equals(v, b[k]) then
return false
end
end
for k, v in pairs(b) do
if not M.table_equals(v, a[k]) then
return false
end
end
return true
end

return M

0 comments on commit 51ec2b4

Please sign in to comment.