From 6e7e80f118c589a009fa1703a284ad292260e3a0 Mon Sep 17 00:00:00 2001 From: Huynh Duc Dung Date: Sat, 3 Feb 2024 00:26:14 +0800 Subject: [PATCH] feat: add new keymap to get previous user prompt --- .../python3/handlers/inplace_chat_handler.py | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/rplugin/python3/handlers/inplace_chat_handler.py b/rplugin/python3/handlers/inplace_chat_handler.py index 500bea20..d3b36dc2 100644 --- a/rplugin/python3/handlers/inplace_chat_handler.py +++ b/rplugin/python3/handlers/inplace_chat_handler.py @@ -176,13 +176,20 @@ def _chat(self): def _set_prompt(self, prompt: str): self.prompt_popup.buffer.lines(prompt) - def _set_user_prompt(self): + def _set_next_user_prompt(self): self.current_user_prompt = (self.current_user_prompt + 1) % len( self.user_prompts ) prompt = list(self.user_prompts.keys())[self.current_user_prompt] self.prompt_popup.buffer.lines(self.user_prompts[prompt]) + def _set_previous_user_prompt(self): + self.current_user_prompt = (self.current_user_prompt - 1) % len( + self.user_prompts + ) + prompt = list(self.user_prompts.keys())[self.current_user_prompt] + self.prompt_popup.buffer.lines(self.user_prompts[prompt]) + def _toggle_model(self): if self.model == MODEL_GPT4: self.model = MODEL_GPT35_TURBO @@ -246,10 +253,16 @@ def _set_keymaps(self): "i", "", lambda: (self.nvim.feed(""), self._chat()) ) + self.prompt_popup.map( + "n", + "", + lambda: self._set_next_user_prompt(), + ) + self.prompt_popup.map( "n", "", - lambda: self._set_user_prompt(), + lambda: self._set_previous_user_prompt(), ) for i, popup in enumerate(self.popups): @@ -286,7 +299,8 @@ def _set_help_content(self): "Prompt Binding:", " ': Set prompt to SIMPLE_DOCSTRING", " s: Set prompt to SEPARATE", - " : Set prompt to next item in user prompts", + " : Get the previous user prompt", + " : Set prompt to next item in user prompts", "", "Model:", " : Toggle AI model",