From 7d859141b4aacec7567ee5822b2dca5dece39877 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Mon, 1 Jan 2024 10:57:27 -0800 Subject: [PATCH] feat: arrowup edit message shortcut --- src/lib/components/chat/MessageInput.svelte | 18 ++++++++++++++++++ .../chat/Messages/UserMessage.svelte | 8 ++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/lib/components/chat/MessageInput.svelte b/src/lib/components/chat/MessageInput.svelte index bb941c90e..d2fe8ca29 100644 --- a/src/lib/components/chat/MessageInput.svelte +++ b/src/lib/components/chat/MessageInput.svelte @@ -298,6 +298,24 @@ submitPrompt(prompt); } }} + on:keydown={(e) => { + if (prompt === '' && e.key == 'ArrowUp') { + e.preventDefault(); + + const userMessageElement = [ + ...document.getElementsByClassName('user-message') + ]?.at(-1); + + const editButton = [ + ...document.getElementsByClassName('edit-user-message-button') + ]?.at(-1); + + console.log(userMessageElement); + + userMessageElement.scrollIntoView({ block: 'center' }); + editButton?.click(); + } + }} rows="1" on:input={(e) => { e.target.style.height = ''; diff --git a/src/lib/components/chat/Messages/UserMessage.svelte b/src/lib/components/chat/Messages/UserMessage.svelte index a760ce3a8..693d20e23 100644 --- a/src/lib/components/chat/Messages/UserMessage.svelte +++ b/src/lib/components/chat/Messages/UserMessage.svelte @@ -24,6 +24,8 @@ editElement.style.height = ''; editElement.style.height = `${editElement.scrollHeight}px`; + + editElement?.focus(); }; const editMessageConfirmHandler = async () => { @@ -43,7 +45,9 @@
- You +
+ You +
{ editMessageHandler(); }}