From 1a4692172eaf68afff8de2fe0a4e431f5250d704 Mon Sep 17 00:00:00 2001 From: Tomas Slusny Date: Wed, 1 May 2024 06:20:12 +0200 Subject: [PATCH] feat: Add 'replace' layout that replaces current buffer in window (#295) --- README.md | 2 +- lua/CopilotChat/chat.lua | 3 +++ lua/CopilotChat/config.lua | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a760303f..a5fd09cf 100644 --- a/README.md +++ b/README.md @@ -260,7 +260,7 @@ Also see [here](/lua/CopilotChat/config.lua): -- default window options window = { - layout = 'vertical', -- 'vertical', 'horizontal', 'float' + layout = 'vertical', -- 'vertical', 'horizontal', 'float', 'replace' width = 0.5, -- fractional width of parent, or absolute width in columns when > 1 height = 0.5, -- fractional height of parent, or absolute height in rows when > 1 -- Options below only apply to floating windows diff --git a/lua/CopilotChat/chat.lua b/lua/CopilotChat/chat.lua index 3b8a3540..243303a2 100644 --- a/lua/CopilotChat/chat.lua +++ b/lua/CopilotChat/chat.lua @@ -153,6 +153,9 @@ function Chat:open(config) self.winnr = vim.api.nvim_get_current_win() vim.api.nvim_win_set_buf(self.winnr, self.bufnr) vim.api.nvim_set_current_win(orig) + elseif layout == 'replace' then + self.winnr = vim.api.nvim_get_current_win() + vim.api.nvim_win_set_buf(self.winnr, self.bufnr) end vim.wo[self.winnr].wrap = true diff --git a/lua/CopilotChat/config.lua b/lua/CopilotChat/config.lua index 3cd586a1..3fa28d00 100644 --- a/lua/CopilotChat/config.lua +++ b/lua/CopilotChat/config.lua @@ -179,7 +179,7 @@ return { -- default window options window = { - layout = 'vertical', -- 'vertical', 'horizontal', 'float' + layout = 'vertical', -- 'vertical', 'horizontal', 'float', 'replace' width = 0.5, -- fractional width of parent, or absolute width in columns when > 1 height = 0.5, -- fractional height of parent, or absolute height in rows when > 1 -- Options below only apply to floating windows