Files
cinny/src/app/hooks/useFilePasteHandler.ts
T
jaredandClaude Opus 5 f7d40460f5 paste: when the clipboard carries files, never let the HTML/URL fragment into the composer (#132)
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
2026-09-19 17:28:25 -04:00

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],
);