From d3800d43342252f1bc2ecd3ddb0f905dfb90042e Mon Sep 17 00:00:00 2001 From: Martin Bielik Date: Fri, 21 Apr 2023 18:16:58 +0200 Subject: move prompt to python --- autoload/vim_ai.vim | 13 +++++++------ py/chat.py | 11 ++++++++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/autoload/vim_ai.vim b/autoload/vim_ai.vim index 55439b2..288810f 100644 --- a/autoload/vim_ai.vim +++ b/autoload/vim_ai.vim @@ -119,18 +119,19 @@ function! vim_ai#AIChatRun(is_selection, ...) range if &filetype != 'aichat' 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 - 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 - 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() -- cgit v1.2.3