Skip to content

Feature: Insert the copied image from the browser as a file #8681

Description

@levensta

Description

There are several ways to copy and paste an image. You can copy it from the file system or copy it from the browser using the context menu. When copying an image from a browser, the image is not pasted as a file. Instead, an HTML import is performed

copy-from-browser.mov

This happens because when you copy an image from a web page via the context menu, the browser contains two mime types in the clipboard at the same time: text/html and the file type

Image

evetFiles function returns false for the hasTextContent flag because DataTransfer has text/html type and the DRAG_DROP_PASTE dispatch is skipped https://github.com/facebook/lexical/blob/main/packages/lexical-rich-text/src/index.ts#L1292-L1298

Impact

The current limitation prevents images copied from the browser from being pasted as a file, even though the clipboard contains a file. The DRAG_DROP_PASTE command handler will never trigger. Pasting via HTML may not be desirable if the user wants to strictly control the sources of images

To support this scenario, you have to override the PASTE_COMMAND, although it would be nice to have this kind of paste built-in. Alternatively, the eventFiles function could be parameterized so that overriding PASTE_COMMAND in a custom editor doesn't duplicate the existing logic, but reuses it

Metadata

Metadata

Assignees

No one assigned

    Labels

    copy+pasteRelates to Lexical Copy/PasteenhancementImprovement over existing feature

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions