fix: input issue

This commit is contained in:
Timothy Jaeryang Baek 2024-11-25 22:43:34 -08:00
parent c4f82309dc
commit f9e24968e3
2 changed files with 60 additions and 59 deletions

View File

@ -592,29 +592,6 @@
placeholder={placeholder ? placeholder : $i18n.t('Send a Message')} placeholder={placeholder ? placeholder : $i18n.t('Send a Message')}
largeTextAsFile={$settings?.largeTextAsFile ?? false} largeTextAsFile={$settings?.largeTextAsFile ?? false}
bind:value={prompt} bind:value={prompt}
on:enter={async (e) => {
const commandsContainerElement =
document.getElementById('commands-container');
if (commandsContainerElement) {
e.preventDefault();
const commandOptionButton = [
...document.getElementsByClassName('selected-command-option-button')
]?.at(-1);
if (commandOptionButton) {
commandOptionButton?.click();
return;
}
}
if (prompt !== '') {
dispatch('submit', prompt);
}
}}
on:keypress={(e) => {
e = e.detail.event;
}}
on:keydown={async (e) => { on:keydown={async (e) => {
e = e.detail.event; e = e.detail.event;
@ -657,6 +634,7 @@
editButton?.click(); editButton?.click();
} }
if (commandsContainerElement) {
if (commandsContainerElement && e.key === 'ArrowUp') { if (commandsContainerElement && e.key === 'ArrowUp') {
e.preventDefault(); e.preventDefault();
commandsElement.selectUp(); commandsElement.selectUp();
@ -687,6 +665,40 @@
commandOptionButton?.click(); commandOptionButton?.click();
} }
if (commandsContainerElement && e.key === 'Enter') {
e.preventDefault();
const commandOptionButton = [
...document.getElementsByClassName('selected-command-option-button')
]?.at(-1);
if (commandOptionButton) {
commandOptionButton?.click();
} else {
document.getElementById('send-message-button')?.click();
}
}
} else {
if (
!$mobile ||
!(
'ontouchstart' in window ||
navigator.maxTouchPoints > 0 ||
navigator.msMaxTouchPoints > 0
)
) {
// Prevent Enter key from creating a new line
if (e.keyCode === 13 && !e.shiftKey) {
e.preventDefault();
}
// Submit the prompt when Enter key is pressed
if (prompt !== '' && e.keyCode === 13 && !e.shiftKey) {
dispatch('submit', prompt);
}
}
}
if (e.key === 'Escape') { if (e.key === 'Escape') {
console.log('Escape'); console.log('Escape');
atSelectedModel = undefined; atSelectedModel = undefined;

View File

@ -171,11 +171,10 @@
eventDispatch('focus', { event }); eventDispatch('focus', { event });
return false; return false;
}, },
keypress: (view, event) => { keyup: (view, event) => {
eventDispatch('keypress', { event }); eventDispatch('keyup', { event });
return false; return false;
}, },
keydown: (view, event) => { keydown: (view, event) => {
// Handle Tab Key // Handle Tab Key
if (event.key === 'Tab') { if (event.key === 'Tab') {
@ -217,22 +216,12 @@
// Handle shift + Enter for a line break // Handle shift + Enter for a line break
if (shiftEnter) { if (shiftEnter) {
if (event.key === 'Enter' && event.shiftKey) { if (event.key === 'Enter' && event.shiftKey && !event.ctrlKey && !event.metaKey) {
editor.commands.setHardBreak(); // Insert a hard break editor.commands.setHardBreak(); // Insert a hard break
view.dispatch(view.state.tr.scrollIntoView()); // Move viewport to the cursor view.dispatch(view.state.tr.scrollIntoView()); // Move viewport to the cursor
event.preventDefault(); event.preventDefault();
return true; return true;
} }
if (event.key === 'Enter') {
eventDispatch('enter', { event });
event.preventDefault();
return true;
}
}
if (event.key === 'Enter') {
eventDispatch('enter', { event });
event.preventDefault();
return true;
} }
} }
eventDispatch('keydown', { event }); eventDispatch('keydown', { event });