Compare commits
No commits in common. "13181fa275d5eeedbc70cdbd78fd8346cf852fd3" and "f0e68cb31e0cbeb145026b004b83da8b4d811271" have entirely different histories.
13181fa275
...
f0e68cb31e
@ -101,41 +101,20 @@ setInterval(() => requestIdleCallback(updateTimes), 30000);
|
|||||||
const textBox = chatInputField.textarea;
|
const textBox = chatInputField.textarea;
|
||||||
textBox.addEventListener("paste", async (e) => {
|
textBox.addEventListener("paste", async (e) => {
|
||||||
try {
|
try {
|
||||||
e.preventDefault();
|
const clipboardItems = await navigator.clipboard.read();
|
||||||
const uploadButton = chatInputField.fileUploadGrid;
|
const dt = new DataTransfer();
|
||||||
|
|
||||||
const clipboardItems = await navigator.clipboard.read()
|
|
||||||
|
|
||||||
for (const item of clipboardItems) {
|
for (const item of clipboardItems) {
|
||||||
if (item.types.every(v => v === "text/plain")) {
|
for (const type of item.types.filter(t => !t.startsWith('text/'))) {
|
||||||
const text = await (await item.getType("text/plain")).text();
|
const blob = await item.getType(type);
|
||||||
chatInputField.value += text;
|
dt.items.add(new File([blob], "image.png", { type }));
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item.types.every(t => t.startsWith('text/'))) {
|
|
||||||
console.log("All types are text:", item.types);
|
|
||||||
const codeType = item.types.find(t => !t.startsWith('text/plain') && !t.startsWith('text/html'));
|
|
||||||
let code = await(await item.getType(codeType ?? 'text/plain')).text();
|
|
||||||
|
|
||||||
const minIndentDepth = code.split('\n').reduce((acc, line) => {
|
|
||||||
if (!line.trim()) return acc;
|
|
||||||
const match = line.match(/^(\s*)/);
|
|
||||||
return match ? Math.min(acc, match[1].length) : acc;
|
|
||||||
}, 9000)
|
|
||||||
|
|
||||||
code = code.split('\n').map(line => line.slice(minIndentDepth)).join('\n')
|
|
||||||
|
|
||||||
chatInputField.value += `\`\`\`${codeType?.split('/')?.[1] ?? ''}\n${code}\n\`\`\`\n`;
|
|
||||||
} else {
|
|
||||||
for (const type of item.types.filter(t => !t.startsWith('text/'))) {
|
|
||||||
const blob = await item.getType(type);
|
|
||||||
const name = type.replace('/', '.')
|
|
||||||
uploadButton.uploadsStarted++
|
|
||||||
uploadButton.createTile(new File([blob], name, {type}))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (dt.items.length > 0) {
|
||||||
|
const uploadButton = chatInputField.uploadButton;
|
||||||
|
const input = uploadButton.shadowRoot.querySelector('.file-input');
|
||||||
|
input.files = dt.files;
|
||||||
|
await uploadButton.uploadFiles();
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to read clipboard contents: ", error);
|
console.error("Failed to read clipboard contents: ", error);
|
||||||
}
|
}
|
||||||
@ -144,17 +123,10 @@ chatArea.addEventListener("drop", async (e) => {
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const dt = e.dataTransfer;
|
const dt = e.dataTransfer;
|
||||||
if (dt.items.length > 0) {
|
if (dt.items.length > 0) {
|
||||||
const uploadButton = chatInputField.fileUploadGrid;
|
const uploadButton = chatInputField.uploadButton;
|
||||||
|
const input = uploadButton.shadowRoot.querySelector('.file-input');
|
||||||
for (const item of dt.items) {
|
input.files = dt.files;
|
||||||
if (item.kind === "file") {
|
await uploadButton.uploadFiles();
|
||||||
const file = item.getAsFile();
|
|
||||||
if (file) {
|
|
||||||
uploadButton.uploadsStarted++
|
|
||||||
uploadButton.createTile(file)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
chatArea.addEventListener("dragover", e => {
|
chatArea.addEventListener("dragover", e => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user