summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--autoload/vim_ai.vim21
-rw-r--r--py/chat.py11
2 files changed, 22 insertions, 10 deletions
diff --git a/autoload/vim_ai.vim b/autoload/vim_ai.vim
index 69a0f95..288810f 100644
--- a/autoload/vim_ai.vim
+++ b/autoload/vim_ai.vim
@@ -117,14 +117,21 @@ function! vim_ai#AIChatRun(is_selection, ...) range
let l:lines = getline(a:firstline, a:lastline)
set paste
if &filetype != 'aichat'
- " open chat window
- execute g:vim_ai_chat['ui']['open_chat_command']
- let l:prompt = ""
- if a:0 || a:is_selection
- let l:instruction = a:0 ? a:1 : ""
- let l:prompt = s:MakePrompt(a:is_selection, l:lines, l:instruction, l:options)
+ let l:chat_win_id = bufwinid(s:scratch_buffer_name)
+ if l:chat_win_id != -1
+ " TODO: look for first active chat buffer, in case .aichat file is used
+ " reuse chat in active window
+ call win_gotoid(l:chat_win_id)
+ else
+ " open new chat window
+ execute g:vim_ai_chat['ui']['open_chat_command']
endif
- execute "normal! Gi" . l:prompt
+ endif
+
+ let l:prompt = ""
+ if a:0 || a:is_selection
+ let l:instruction = a:0 ? a:1 : ""
+ let l:prompt = s:MakePrompt(a:is_selection, l:lines, l:instruction, l:options)
endif
let s:last_command = "chat"
diff --git a/py/chat.py b/py/chat.py
index 491b7c2..93a8664 100644
--- a/py/chat.py
+++ b/py/chat.py
@@ -4,6 +4,7 @@ vim.command(f"py3file {plugin_root}/py/utils.py")
config_options = vim.eval("l:options")
config_ui = vim.eval("l:ui")
+prompt = vim.eval("l:prompt").strip()
def initialize_chat_window():
lines = vim.eval('getline(1, "$")')
@@ -21,11 +22,15 @@ def initialize_chat_window():
vim.command("normal! i" + key + "=" + value + "\n")
vim.command("normal! " + ("o" if populates_options else "O"))
vim.command("normal! i>>> user\n")
- vim.command("normal! G")
+
+ vim.command("normal! G")
+ vim_break_undo_sequence()
+ vim.command("redraw")
+
+ if prompt:
+ vim.command("normal! a" + prompt)
vim_break_undo_sequence()
vim.command("redraw")
- else:
- vim_break_undo_sequence()
initialize_chat_window()