This commit is contained in:
Timothy Jaeryang Baek committed 2026-08-11 00:06:21 -06:00
1 parent 79382d1b19
commit 9122c24ea2
3 files changed
+44 -36

No files matched your search

+18 -17
View File
@@ -518,6 +518,7 @@
return true; return true;
}); });
}; };
const withSelectedText = (text: string) => const withSelectedText = (text: string) =>
embedded && selectedText?.trim() embedded && selectedText?.trim()
? `${text}\n\nSelected note text for replace_note_content operations:\n${selectedText.trim()}` ? `${text}\n\nSelected note text for replace_note_content operations:\n${selectedText.trim()}`
@@ -620,8 +621,7 @@
await setDefaults(); await setDefaults();
} }
const chatInput = document.getElementById('chat-input'); messageInput?.focus({ preventScroll: true });
chatInput?.focus();
} else if (!embedded) { } else if (!embedded) {
await goto('/'); await goto('/');
} else { } else {
@@ -670,7 +670,7 @@
await setDefaults(); await setDefaults();
loading = false; loading = false;
await tick(); await tick();
document.getElementById('chat-input')?.focus(); messageInput?.focus({ preventScroll: true });
}; };
const onSelect = async (e) => { const onSelect = async (e) => {
@@ -1212,7 +1212,7 @@
if (inputElement) { if (inputElement) {
messageInput?.setText(event.data.text); messageInput?.setText(event.data.text);
inputElement.focus(); messageInput?.focus({ preventScroll: true });
} }
} }
@@ -1389,8 +1389,7 @@
} catch (e) {} } catch (e) {}
} }
const chatInput = document.getElementById('chat-input'); messageInput?.focus({ preventScroll: true });
chatInput?.focus();
}; };
init(); init();
@@ -2002,8 +2001,8 @@
$models.map((m) => m.id).includes(modelId) ? modelId : '' $models.map((m) => m.id).includes(modelId) ? modelId : ''
); );
const chatInput = document.getElementById('chat-input'); await tick();
setTimeout(() => chatInput?.focus(), 0); messageInput?.focus({ preventScroll: true });
}; };
const loadChat = async () => { const loadChat = async () => {
@@ -2643,8 +2642,7 @@
// focus on chat input (skip during voice call to avoid triggering mobile keyboard) // focus on chat input (skip during voice call to avoid triggering mobile keyboard)
if (!$showCallOverlay) { if (!$showCallOverlay) {
const chatInput = document.getElementById('chat-input'); messageInput?.focus({ preventScroll: true });
chatInput?.focus();
} }
saveSessionSelectedModels(); saveSessionSelectedModels();
@@ -2699,13 +2697,13 @@
const message = error?.detail ?? error?.message ?? $i18n.t('Context compaction failed'); const message = error?.detail ?? error?.message ?? $i18n.t('Context compaction failed');
toast.error(message, { id: toastId }); toast.error(message, { id: toastId });
} finally { } finally {
document.getElementById('chat-input')?.focus(); messageInput?.focus({ preventScroll: true });
} }
}; };
const handleStatusCommand = () => { const handleStatusCommand = () => {
messageInput?.showStatus(); messageInput?.showStatus();
document.getElementById('chat-input')?.focus(); messageInput?.focus({ preventScroll: true });
}; };
const handleModelCommand = (modelId = '') => { const handleModelCommand = (modelId = '') => {
@@ -2720,7 +2718,7 @@
); );
messageInput?.setText(''); messageInput?.setText('');
prompt = ''; prompt = '';
document.getElementById('chat-input')?.focus(); messageInput?.focus({ preventScroll: true });
return; return;
} }
@@ -2729,7 +2727,7 @@
toast.error(`Model not found: ${modelId}`); toast.error(`Model not found: ${modelId}`);
messageInput?.setText(''); messageInput?.setText('');
prompt = ''; prompt = '';
document.getElementById('chat-input')?.focus(); messageInput?.focus({ preventScroll: true });
return; return;
} }
@@ -2739,7 +2737,7 @@
toast.success(`Model switched to: ${model.id}`); toast.success(`Model switched to: ${model.id}`);
messageInput?.setText(''); messageInput?.setText('');
prompt = ''; prompt = '';
document.getElementById('chat-input')?.focus(); messageInput?.focus({ preventScroll: true });
}; };
const handleForkChat = async (messageId: string | null = null) => { const handleForkChat = async (messageId: string | null = null) => {
@@ -2783,7 +2781,7 @@
} catch (error) { } catch (error) {
toast.error(`${error}`, { id: toastId }); toast.error(`${error}`, { id: toastId });
} finally { } finally {
document.getElementById('chat-input')?.focus(); messageInput?.focus({ preventScroll: true });
} }
}; };
@@ -4205,7 +4203,10 @@
</div> </div>
</div> </div>
{/if} {/if}
<div id={embedded ? messageInputDropzoneId : undefined} class="pb-2 z-10"> <div
id={embedded ? messageInputDropzoneId : undefined}
class="pb-2 z-10"
>
<MessageInput <MessageInput
bind:this={messageInput} bind:this={messageInput}
{history} {history}
+18 -15
View File
@@ -357,10 +357,14 @@
if (chatInput) { if (chatInput) {
chatInputElement.replaceVariables(variables); chatInputElement.replaceVariables(variables);
chatInputElement.focus(); focus();
} }
}; };
export const focus = (options: FocusOptions = {}) => {
chatInputElement?.focus(options);
};
export const setText = async (text?: string, cb?: (text: string) => void) => { export const setText = async (text?: string, cb?: (text: string) => void) => {
const chatInput = document.getElementById('chat-input'); const chatInput = document.getElementById('chat-input');
@@ -371,7 +375,7 @@
chatInputElement?.setText(text); chatInputElement?.setText(text);
if (!$showCallOverlay) { if (!$showCallOverlay) {
chatInputElement?.focus(); focus();
} }
if (text !== '') { if (text !== '') {
@@ -386,7 +390,7 @@
export const showStatus = async () => { export const showStatus = async () => {
showStatusPanel = true; showStatusPanel = true;
await tick(); await tick();
document.getElementById('chat-input')?.focus(); focus({ preventScroll: true });
}; };
const formatTokenCount = (value: number) => { const formatTokenCount = (value: number) => {
@@ -536,7 +540,7 @@
await tick(); await tick();
if (chatInput) { if (chatInput) {
chatInput.focus(); focus({ preventScroll: true });
chatInput.dispatchEvent(new Event('input')); chatInput.dispatchEvent(new Event('input'));
const words = extractCurlyBraceWords(prompt); const words = extractCurlyBraceWords(prompt);
@@ -604,7 +608,7 @@
await tick(); await tick();
await inputVariableHandler(text); await inputVariableHandler(text);
await tick(); await tick();
document.getElementById('chat-input')?.focus(); focus({ preventScroll: true });
}; };
let command = ''; let command = '';
@@ -1220,7 +1224,7 @@
atSelectedModel = data; atSelectedModel = data;
} }
document.getElementById('chat-input')?.focus(); focus({ preventScroll: true });
}, },
insertTextHandler: insertTextAtCursor, insertTextHandler: insertTextAtCursor,
@@ -1293,7 +1297,7 @@
atSelectedModel = data; atSelectedModel = data;
} }
document.getElementById('chat-input')?.focus(); focus({ preventScroll: true });
}, },
insertTextHandler: insertTextAtCursor, insertTextHandler: insertTextAtCursor,
@@ -1331,7 +1335,7 @@
atSelectedModel = data; atSelectedModel = data;
} }
document.getElementById('chat-input')?.focus(); focus({ preventScroll: true });
}, },
insertTextHandler: insertTextAtCursor, insertTextHandler: insertTextAtCursor,
@@ -1363,7 +1367,7 @@
render: getSuggestionRenderer(CommandSuggestionList, { render: getSuggestionRenderer(CommandSuggestionList, {
i18n, i18n,
onSelect: (e) => { onSelect: (e) => {
document.getElementById('chat-input')?.focus(); focus({ preventScroll: true });
}, },
insertTextHandler: insertTextAtCursor, insertTextHandler: insertTextAtCursor,
@@ -1382,7 +1386,7 @@
render: getSuggestionRenderer(CommandSuggestionList, { render: getSuggestionRenderer(CommandSuggestionList, {
i18n, i18n,
onSelect: (e) => { onSelect: (e) => {
document.getElementById('chat-input')?.focus(); focus({ preventScroll: true });
}, },
insertTextHandler: insertTextAtCursor, insertTextHandler: insertTextAtCursor,
@@ -1468,7 +1472,7 @@
}} }}
onClose={async () => { onClose={async () => {
await tick(); await tick();
chatInputElement?.focus(); focus();
}} }}
/> />
@@ -1544,7 +1548,7 @@
recording = false; recording = false;
await tick(); await tick();
document.getElementById('chat-input')?.focus(); focus({ preventScroll: true });
}} }}
onConfirm={async (data) => { onConfirm={async (data) => {
const { text, filename } = data; const { text, filename } = data;
@@ -1554,7 +1558,7 @@
await tick(); await tick();
await insertTextAtCursor(`${text}`); await insertTextAtCursor(`${text}`);
await tick(); await tick();
document.getElementById('chat-input')?.focus(); focus({ preventScroll: true });
if ($settings?.speechAutoSend ?? false) { if ($settings?.speechAutoSend ?? false) {
dispatch('submit', prompt); dispatch('submit', prompt);
@@ -1565,7 +1569,6 @@
<form <form
class="w-full flex flex-col gap-1.5 {recording ? 'hidden' : ''}" class="w-full flex flex-col gap-1.5 {recording ? 'hidden' : ''}"
on:submit|preventDefault={() => { on:submit|preventDefault={() => {
// check if selectedModels support image input
dispatch('submit', prompt); dispatch('submit', prompt);
}} }}
> >
@@ -2424,7 +2427,7 @@
{/if} {/if}
{/if} {/if}
{#if prompt === '' && files.length === 0 && ($_user?.role === 'admin' || ($_user?.permissions?.chat?.call ?? true))} {#if !embedded && prompt === '' && files.length === 0 && ($_user?.role === 'admin' || ($_user?.permissions?.chat?.call ?? true))}
<div class=" flex items-center"> <div class=" flex items-center">
<!-- {$i18n.t('Call')} --> <!-- {$i18n.t('Call')} -->
<Tooltip content={$i18n.t('Voice mode')}> <Tooltip content={$i18n.t('Voice mode')}>
@@ -576,7 +576,7 @@
} }
}; };
export const focus = () => { export const focus = (options: FocusOptions = {}) => {
if (editor && editor.view) { if (editor && editor.view) {
// Check if the editor is destroyed // Check if the editor is destroyed
if (editor.isDestroyed) { if (editor.isDestroyed) {
@@ -584,9 +584,13 @@
} }
try { try {
editor.view.focus(); if (options.preventScroll && editor.view.dom instanceof HTMLElement) {
// Scroll to the current selection editor.view.dom.focus(options);
editor.view.dispatch(editor.view.state.tr.scrollIntoView()); } else {
editor.view.focus();
// Scroll to the current selection
editor.view.dispatch(editor.view.state.tr.scrollIntoView());
}
} catch (e) { } catch (e) {
// sometimes focusing throws an error, ignore // sometimes focusing throws an error, ignore
console.warn('Error focusing editor', e); console.warn('Error focusing editor', e);