feat: Bypass file creation with CTRL + SHIFT + V

Co-Authored-By: Classic298 <27028174+Classic298@users.noreply.github.com>
This commit is contained in:
Timothy Jaeryang Baek 2025-05-26 22:10:35 +04:00
parent fc5dfd3536
commit a0d034fa7c

View File

@ -109,7 +109,9 @@
let commandsElement; let commandsElement;
let inputFiles; let inputFiles;
let dragged = false; let dragged = false;
let shiftKey = false;
let user = null; let user = null;
export let placeholder = ''; export let placeholder = '';
@ -352,13 +354,6 @@
}); });
}; };
const handleKeyDown = (event: KeyboardEvent) => {
if (event.key === 'Escape') {
console.log('Escape');
dragged = false;
}
};
const onDragOver = (e) => { const onDragOver = (e) => {
e.preventDefault(); e.preventDefault();
@ -389,6 +384,30 @@
dragged = false; dragged = false;
}; };
const onKeyDown = (e) => {
if (e.key === 'Shift') {
shiftKey = true;
}
if (e.key === 'Escape') {
console.log('Escape');
dragged = false;
}
};
const onKeyUp = (e) => {
if (e.key === 'Shift') {
shiftKey = false;
}
};
const onFocus = () => {};
const onBlur = () => {
shiftKey = false;
selectedChatId = null;
};
onMount(async () => { onMount(async () => {
loaded = true; loaded = true;
@ -397,7 +416,11 @@
chatInput?.focus(); chatInput?.focus();
}, 0); }, 0);
window.addEventListener('keydown', handleKeyDown); window.addEventListener('keydown', onKeyDown);
window.addEventListener('keyup', onKeyUp);
window.addEventListener('focus', onFocus);
window.addEventListener('blur', onBlur);
await tick(); await tick();
@ -410,7 +433,11 @@
onDestroy(() => { onDestroy(() => {
console.log('destroy'); console.log('destroy');
window.removeEventListener('keydown', handleKeyDown); window.removeEventListener('keydown', onKeyDown);
window.removeEventListener('keyup', onKeyUp);
window.removeEventListener('focus', onFocus);
window.removeEventListener('blur', onBlur);
const dropzoneElement = document.getElementById('chat-container'); const dropzoneElement = document.getElementById('chat-container');
@ -691,7 +718,7 @@
navigator.msMaxTouchPoints > 0 navigator.msMaxTouchPoints > 0
))} ))}
placeholder={placeholder ? placeholder : $i18n.t('Send a Message')} placeholder={placeholder ? placeholder : $i18n.t('Send a Message')}
largeTextAsFile={$settings?.largeTextAsFile ?? false} largeTextAsFile={($settings?.largeTextAsFile ?? false) && !shiftKey}
autocomplete={$config?.features?.enable_autocomplete_generation && autocomplete={$config?.features?.enable_autocomplete_generation &&
($settings?.promptAutocomplete ?? false)} ($settings?.promptAutocomplete ?? false)}
generateAutoCompletion={async (text) => { generateAutoCompletion={async (text) => {
@ -873,7 +900,7 @@
reader.readAsDataURL(blob); reader.readAsDataURL(blob);
} else if (item.type === 'text/plain') { } else if (item.type === 'text/plain') {
if ($settings?.largeTextAsFile ?? false) { if (($settings?.largeTextAsFile ?? false) && !shiftKey) {
const text = clipboardData.getData('text/plain'); const text = clipboardData.getData('text/plain');
if (text.length > PASTED_TEXT_CHARACTER_LIMIT) { if (text.length > PASTED_TEXT_CHARACTER_LIMIT) {
@ -1104,7 +1131,7 @@
reader.readAsDataURL(blob); reader.readAsDataURL(blob);
} else if (item.type === 'text/plain') { } else if (item.type === 'text/plain') {
if ($settings?.largeTextAsFile ?? false) { if (($settings?.largeTextAsFile ?? false) && !shiftKey) {
const text = clipboardData.getData('text/plain'); const text = clipboardData.getData('text/plain');
if (text.length > PASTED_TEXT_CHARACTER_LIMIT) { if (text.length > PASTED_TEXT_CHARACTER_LIMIT) {