Skip to content

Commit 675a64b

Browse files
authored
feat(GpChatPaste): focus chat if already open (resolves #86) (#87)
* feat(GpChatPaste): focus chat if already open (resolves #86) * refactor: simplify the buf reuse logic
1 parent acccba7 commit 675a64b

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

lua/gp/init.lua

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1762,7 +1762,19 @@ M.cmd.ChatPaste = function(params)
17621762
local target = M.resolve_buf_target(params)
17631763

17641764
last = vim.fn.resolve(last)
1765-
local buf = M.open_buf(last, target, M._toggle_kind.chat, true)
1765+
local buf = M._H.get_buffer(last)
1766+
local win_found = false
1767+
if buf then
1768+
for _, w in ipairs(vim.api.nvim_list_wins()) do
1769+
if vim.api.nvim_win_get_buf(w) == buf then
1770+
vim.api.nvim_set_current_win(w)
1771+
vim.api.nvim_set_current_buf(buf)
1772+
win_found = true
1773+
break
1774+
end
1775+
end
1776+
end
1777+
buf = win_found and buf or M.open_buf(last, target, M._toggle_kind.chat, true)
17661778

17671779
M.append_selection(params, cbuf, buf)
17681780
M._H.feedkeys("G", "x")

0 commit comments

Comments
 (0)