Skip to content

Commit

Permalink
feat: add new keymap to get previous user prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
jellydn committed Feb 2, 2024
1 parent b68c352 commit 6e7e80f
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions rplugin/python3/handlers/inplace_chat_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -246,10 +253,16 @@ def _set_keymaps(self):
"i", "<C-s>", lambda: (self.nvim.feed("<Esc>"), self._chat())
)

self.prompt_popup.map(
"n",
"<C-n>",
lambda: self._set_next_user_prompt(),
)

self.prompt_popup.map(
"n",
"<C-p>",
lambda: self._set_user_prompt(),
lambda: self._set_previous_user_prompt(),
)

for i, popup in enumerate(self.popups):
Expand Down Expand Up @@ -286,7 +299,8 @@ def _set_help_content(self):
"Prompt Binding:",
" ': Set prompt to SIMPLE_DOCSTRING",
" s: Set prompt to SEPARATE",
" <C-p>: Set prompt to next item in user prompts",
" <C-p>: Get the previous user prompt",
" <C-n>: Set prompt to next item in user prompts",
"",
"Model:",
" <C-g>: Toggle AI model",
Expand Down

0 comments on commit 6e7e80f

Please sign in to comment.