From cae1bfe737cbe2365cb9d8788093eaa758dcfb20 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Mon, 8 Jan 2024 18:10:23 -0800 Subject: [PATCH] feat: regenerate keyboard shortcut --- src/lib/components/chat/MessageInput.svelte | 14 ++++++++++++++ .../chat/Messages/ResponseMessage.svelte | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/lib/components/chat/MessageInput.svelte b/src/lib/components/chat/MessageInput.svelte index 34f4de18..72782da9 100644 --- a/src/lib/components/chat/MessageInput.svelte +++ b/src/lib/components/chat/MessageInput.svelte @@ -442,6 +442,20 @@ } }} on:keydown={async (e) => { + const isCtrlPressed = e.ctrlKey || e.metaKey; // metaKey is for Cmd key on Mac + + // Check if Ctrl + R is pressed + if (prompt === '' && isCtrlPressed && e.key.toLowerCase() === 'r') { + e.preventDefault(); + console.log('regenerate'); + + const regenerateButton = [ + ...document.getElementsByClassName('regenerate-response-button') + ]?.at(-1); + + regenerateButton?.click(); + } + if (prompt === '' && e.key == 'ArrowUp') { e.preventDefault(); diff --git a/src/lib/components/chat/Messages/ResponseMessage.svelte b/src/lib/components/chat/Messages/ResponseMessage.svelte index 65efd7c6..4dfcd61d 100644 --- a/src/lib/components/chat/Messages/ResponseMessage.svelte +++ b/src/lib/components/chat/Messages/ResponseMessage.svelte @@ -508,7 +508,7 @@ type="button" class="{isLastMessage ? 'visible' - : 'invisible group-hover:visible'} p-1 rounded dark:hover:bg-gray-800 transition" + : 'invisible group-hover:visible'} p-1 rounded dark:hover:bg-gray-800 transition regenerate-response-button" on:click={regenerateResponse} >