Skip to content

Commit

Permalink
handle pasted text as file
Browse files Browse the repository at this point in the history
  • Loading branch information
hannahblair committed Dec 5, 2024
1 parent a623faf commit 1910029
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion js/multimodaltextbox/shared/MultimodalTextbox.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
export let upload: Client["upload"];
export let stream_handler: Client["stream"];
export let file_count: "single" | "multiple" | "directory" = "multiple";
export let max_text_length = 1000;
let upload_component: Upload;
let hidden_upload: HTMLInputElement;
Expand Down Expand Up @@ -194,9 +195,23 @@
dispatch("submit");
}
function handle_paste(event: ClipboardEvent): void {
async function handle_paste(event: ClipboardEvent): Promise<void> {
if (!event.clipboardData) return;
const items = event.clipboardData.items;
const text = event.clipboardData.getData("text");
if (text && text.length > max_text_length) {
event.preventDefault();
const file = new window.File([text], "pasted_text.txt", {
type: "text/plain",
lastModified: Date.now()
});
if (upload_component) {
upload_component.load_files([file]);
}
return;
}
for (let index in items) {
const item = items[index];
if (item.kind === "file" && item.type.includes("image")) {
Expand Down

0 comments on commit 1910029

Please sign in to comment.