From 9295ac5d1d4b556247f0b529d962392f354bc9a7 Mon Sep 17 00:00:00 2001 From: Wei Meng Date: Thu, 3 Jul 2025 15:28:19 +0800 Subject: [PATCH 1/2] fixes for full diff mode - switch off diff mode of source buffer on exit - fix off-by-one error when patching lines - set correct filetype for diff buffer --- lua/CopilotChat/config/mappings.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lua/CopilotChat/config/mappings.lua b/lua/CopilotChat/config/mappings.lua index baf2f82c..2f64710e 100644 --- a/lua/CopilotChat/config/mappings.lua +++ b/lua/CopilotChat/config/mappings.lua @@ -349,6 +349,8 @@ return { if copilot.config.mappings.show_diff.full_diff then local modified = utils.buf_valid(diff.bufnr) and vim.api.nvim_buf_get_lines(diff.bufnr, 0, -1, false) or {} + opts.syntax = diff.filetype + -- Apply all diffs from same file if #modified > 0 then -- Find all diffs from the same file in this section @@ -376,7 +378,7 @@ return { end local change_lines = vim.split(file_diff.change, '\n') for i, line in ipairs(change_lines) do - table.insert(modified, start_idx + i, line) + table.insert(modified, start_idx + i - 1, line) end end @@ -400,6 +402,10 @@ return { end opts.on_hide = function() + vim.api.nvim_win_call(vim.fn.bufwinid(diff.bufnr), function() + vim.cmd('diffoff') + end) + vim.api.nvim_win_call(copilot.chat.winnr, function() vim.cmd('diffoff') end) From 1b489a75d82f12b53fe6de08917e24c5425fefb5 Mon Sep 17 00:00:00 2001 From: Wei Meng Date: Fri, 4 Jul 2025 13:44:57 +0800 Subject: [PATCH 2/2] remove extra empty line at end of file in diff mode --- lua/CopilotChat/ui/overlay.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/lua/CopilotChat/ui/overlay.lua b/lua/CopilotChat/ui/overlay.lua index 9b70cb5e..e55b867f 100644 --- a/lua/CopilotChat/ui/overlay.lua +++ b/lua/CopilotChat/ui/overlay.lua @@ -39,7 +39,6 @@ function Overlay:show(text, winnr, filetype, syntax, on_show, on_hide) self:validate() vim.api.nvim_win_set_hl_ns(winnr, self.hl_ns) - text = text .. '\n' self.cursor = vim.api.nvim_win_get_cursor(winnr) vim.api.nvim_win_set_buf(winnr, self.bufnr)