summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
Diffstat (limited to 'autoload')
-rw-r--r--autoload/vim_ai.vim21
1 files changed, 14 insertions, 7 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"