Skip to content

Commit

Permalink
global editor buffer for proper return
Browse files Browse the repository at this point in the history
  • Loading branch information
dqnk committed May 19, 2024
1 parent 9f90464 commit 1aa48d5
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lua/chatgpt/flows/chat/base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 1aa48d5

Please sign in to comment.