ajout d'image

This commit is contained in:
2026-05-26 18:48:25 +02:00
parent a1c4365f39
commit 600f2b6196
8 changed files with 226 additions and 1 deletions
+27
View File
@@ -0,0 +1,27 @@
export function handleImagePaste(event: ClipboardEvent, onImage: (markdown: string) => void): void {
const items = event.clipboardData?.items;
if (!items) return;
for (const item of Array.from(items)) {
if (item.type.startsWith('image/')) {
const file = item.getAsFile();
if (!file) continue;
event.preventDefault();
const reader = new FileReader();
reader.onload = (e) => onImage(`![image](${e.target!.result as string})`);
reader.readAsDataURL(file);
return;
}
}
}
export function insertAtSelection(
textarea: HTMLTextAreaElement,
currentValue: string,
start: number,
end: number,
insertion: string,
): string {
const next = currentValue.slice(0, start) + insertion + currentValue.slice(end);
setTimeout(() => { textarea.selectionStart = textarea.selectionEnd = start + insertion.length; });
return next;
}