Skip to content

Commit

Permalink
visual selection in chat
Browse files Browse the repository at this point in the history
  • Loading branch information
dqnk committed May 19, 2024
1 parent df53728 commit 9f90464
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lua/chatgpt/flows/chat/base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ function Chat:init()
-- quit indicator
self.active = true

self.editor_bufnr = nil

-- UI ELEMENTS
self.layout = nil
self.chat_panel = nil
Expand Down Expand Up @@ -736,6 +738,13 @@ function Chat:get_layout_params()
end

function Chat:open()
local editor_bufnr = vim.api.nvim_get_current_buf()
self.editor_bufnr = editor_bufnr
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)
end
self.settings_panel = Settings.get_settings_panel("chat_completions", self.params)
self.help_panel = Help.get_help_panel("chat")
self.sessions_panel = Sessions.get_panel(function(session)
Expand Down Expand Up @@ -1017,6 +1026,8 @@ function Chat:open()
self.chat_input:on(event.QuitPre, function()
self.active = false
end)

vim.api.nvim_buf_set_lines(self.chat_input.bufnr, -1, -1, false, visual_lines)
end

function Chat:open_system_panel()
Expand All @@ -1038,6 +1049,15 @@ function Chat:hide()
end

function Chat:show()
local editor_bufnr = vim.api.nvim_get_current_buf()
self.editor_bufnr = editor_bufnr
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)
end
vim.api.nvim_buf_set_lines(self.chat_input.bufnr, -1, -1, false, visual_lines)

self:redraw(true)
self.layout:show()
end
Expand Down

0 comments on commit 9f90464

Please sign in to comment.