From 1aa48d59eb51852c349c303bd492f5c5f708922f Mon Sep 17 00:00:00 2001 From: dqnk <64268180+dqnk@users.noreply.github.com> Date: Sun, 19 May 2024 11:37:22 +0200 Subject: [PATCH] global editor buffer for proper return --- lua/chatgpt/flows/chat/base.lua | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lua/chatgpt/flows/chat/base.lua b/lua/chatgpt/flows/chat/base.lua index 438bace..14525cc 100644 --- a/lua/chatgpt/flows/chat/base.lua +++ b/lua/chatgpt/flows/chat/base.lua @@ -30,7 +30,9 @@ function Chat:init() -- quit indicator self.active = true + -- EDITOR BUFNR self.editor_bufnr = nil + self.editor_win_id = nil -- UI ELEMENTS self.layout = nil @@ -738,12 +740,12 @@ function Chat:get_layout_params() end function Chat:open() - local editor_bufnr = vim.api.nvim_get_current_buf() - self.editor_bufnr = editor_bufnr + self.editor_win_id = vim.api.nvim_get_current_win() + self.editor_bufnr = vim.api.nvim_get_current_buf() local visual_lines = {} -- if in visual, visual line, visual block modes if vim.fn.mode() == "v" or vim.fn.mode() == "V" or vim.fn.mode() == "\22" then - visual_lines, _, _, _, _ = Utils.get_visual_lines(editor_bufnr) + visual_lines, _, _, _, _ = Utils.get_visual_lines(self.editor_bufnr) end self.settings_panel = Settings.get_settings_panel("chat_completions", self.params) self.help_panel = Help.get_help_panel("chat") @@ -1046,15 +1048,17 @@ end function Chat:hide() self.layout:hide() + vim.api.nvim_set_current_buf(self.editor_bufnr) + vim.api.nvim_win_set_buf(self.editor_win_id, self.editor_bufnr) end function Chat:show() - local editor_bufnr = vim.api.nvim_get_current_buf() - self.editor_bufnr = editor_bufnr + self.editor_win_id = vim.api.nvim_get_current_win() + self.editor_bufnr = vim.api.nvim_get_current_buf() local visual_lines = {} -- if in visual, visual line, visual block modes if vim.fn.mode() == "v" or vim.fn.mode() == "V" or vim.fn.mode() == "\22" then - visual_lines, _, _, _, _ = Utils.get_visual_lines(editor_bufnr) + visual_lines, _, _, _, _ = Utils.get_visual_lines(self.editor_bufnr) end vim.api.nvim_buf_set_lines(self.chat_input.bufnr, -1, -1, false, visual_lines)