ajout d'image
This commit is contained in:
@@ -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(``);
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user