fix up/down bug

This commit is contained in:
Andrei Canta 2023-03-25 19:37:42 +02:00
parent f0fc9644ec
commit 7dde441c8e

View file

@ -154,7 +154,8 @@ export function ChatRoute() {
await db.chats.where({ id: chatId }).modify((chat) => {
chat.description = chatDescription ?? "New Chat";
if (chat.totalTokens) {
chat.totalTokens += createChatDescription.data.usage!.total_tokens;
chat.totalTokens +=
createChatDescription.data.usage!.total_tokens;
} else {
chat.totalTokens = createChatDescription.data.usage!.total_tokens;
}
@ -288,6 +289,9 @@ export function ChatRoute() {
submit();
}
if (event.code === "ArrowUp") {
const { selectionStart, selectionEnd } = event.currentTarget;
if (selectionStart !== selectionEnd) return;
if (selectionStart !== 0) return;
event.preventDefault();
const nextUserMessage = findLast(
messages,
@ -296,6 +300,10 @@ export function ChatRoute() {
setContent(nextUserMessage?.content ?? "");
}
if (event.code === "ArrowDown") {
const { selectionStart, selectionEnd } = event.currentTarget;
if (selectionStart !== selectionEnd) return;
if (selectionStart !== event.currentTarget.value.length)
return;
event.preventDefault();
const lastUserMessage = findLast(
messages,