Verified headless that pasting an image copied from a web page (bitmap + text/html <img src alt> + text/plain URL) already produced only the upload card and an empty composer; make that explicit with a preventDefault so a future editor change can't regress it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PPmy3tPq869XDW4njjVaKA
19 lines
704 B
TypeScript
19 lines
704 B
TypeScript
import { useCallback, ClipboardEventHandler } from 'react';
|
|
import { getDataTransferFiles } from '../utils/dom';
|
|
|
|
export const useFilePasteHandler = (onPaste: (file: File[]) => void): ClipboardEventHandler =>
|
|
useCallback(
|
|
(evt) => {
|
|
const files = getDataTransferFiles(evt.clipboardData);
|
|
if (files) {
|
|
// [Gitea #132] An image copied from a web page arrives with a
|
|
// text/html `<img src=… alt=…>` fragment and a text/plain URL beside
|
|
// the bitmap. Only the file is wanted — stop the editor's own
|
|
// HTML/text insertion so nothing else lands in the composer.
|
|
evt.preventDefault();
|
|
onPaste(files);
|
|
}
|
|
},
|
|
[onPaste],
|
|
);
|