Page MenuHomePhabricator

Copy/Paste of images in Visual editor does not work browser page to browser page as expected
Closed, ResolvedPublic

Description

Hi,

I hope I'm giving enough info on this issue. I'm new to the mediawiki community (and development in general) but I thought I'd log a bug I'd noticed.

Expected behavior: When I right click and "copy" an image in one tab of my browser, that I can go over to the Visual Editor and paste that image into a page that is being edited. Also expected is the ability to drag and drop an image from one tab to the next.

Actual behavior: it does nothing.

See attached video.

Also see previous discussion that led to creation of this issue. https://phabricator.wikimedia.org/T39932

Event Timeline

Restricted Application added a project: Multimedia. · View Herald TranscriptNov 2 2018, 9:17 PM
Restricted Application added a subscriber: Aklapper. · View Herald Transcript

This task seems to cover two different things? Drag and drop (which isn't shown in the video but mentioned in the task summary?), and also copying to your system's clipboard uploading and then pasting/uploading the "Media settings > Upload" dialog in VisualEditor (which does not seem to save the image?).

https://phabricator.wikimedia.org/T39932#4708223 is the relevant information for the latter.

Thedonquixotic renamed this task from Drop and Drop in Visual editor does not work browser page to browser page as expected to Copy/Paste in Visual editor does not work browser page to browser page as expected.Nov 6 2018, 3:29 AM

@Aklapper Task has been renamed to reflect more focused/accurate issue.

@Thedonquixotic: I'm confused. Your video above does not show copying from browser page to browser page, but from some application called Paint (I think?) to a browser page instead.

@Aklapper Apologies again, I uploaded the wrong video. The original was also linked in the previous thread and I'll reupload it here and edit my original issue.

Esanders triaged this task as Low priority.Nov 6 2018, 4:38 PM
Esanders added subscribers: matmarex, Esanders.

Interesting. Turns out that when you copy an image in the browser, it is stored in the clipboard in two formats: as the actual image, and as HTML like this:

<html>
<body>
<!--StartFragment--><img src="https://apod.nasa.gov/apod/image/1705/Arp273Main_HubblePestana_3079.jpg" alt="Image result for galaxy"/><!--EndFragment-->
</body>
</html>

When this is pasted into VisualEditor, we use the HTML instead of the image (ve.ce.Surface.prototype.handleDataTransfer), because:

	// Only look for files if HTML is not available:
	//  - If a file is pasted/dropped it is unlikely it will have HTML fallback (it will have plain text fallback though)
	//  - HTML generated from some clients has an image fallback(!) that is a screenshot of the HTML snippet (e.g. LibreOffice Calc)

Then our paste sanitization strips that HTML down to nothing (since <img> tags using external resources are not possible in wikitext), and then nothing is pasted.

@Thedonquixotic Can you file a separate task about this?

(As a workaround, I guess you can paste into Paint, then copy from Paint.)

Urfiner rescinded a token.
Urfiner awarded a token.
Urfiner added a subscriber: Urfiner.

Pinging stakeholders: It seems to me that a good potential solution would be to use the image (rather than the HTML) if and only if the HTML content only contains metadata node, empty text nodes, and the image(s) themselves. In other words, if the HTML contains any actual content (text or otherwise) other than the image(s), it should be used instead of the image. I have some working fix that I validated by pasting a single image from multiple popular sources, such as Chrome, One Note, and Word. If nobody has objections to the implementation, I'll go ahead and submit a patch.

Sounds reasonable to me.

Change 488993 had a related patch set uploaded (by Juan Osorio (Microsoft); owner: Juan Osorio (Microsoft)):
[VisualEditor/VisualEditor@master] ve.ce.Surface: handles clipboard images with HTML

https://gerrit.wikimedia.org/r/488993

matmarex renamed this task from Copy/Paste in Visual editor does not work browser page to browser page as expected to Copy/Paste of images in Visual editor does not work browser page to browser page as expected.Feb 12 2019, 6:57 PM

Change 488993 merged by jenkins-bot:
[VisualEditor/VisualEditor@master] ve.ce.Surface: handles clipboard images with HTML

https://gerrit.wikimedia.org/r/488993

matmarex removed a project: Multimedia.
Esanders moved this task from Inbox to Low Priority on the Editing QA board.Feb 13 2019, 6:47 PM

Change 490478 had a related patch set uploaded (by Jforrester; owner: Jforrester):
[mediawiki/extensions/VisualEditor@master] Update VE core submodule to master (1d9e3a217)

https://gerrit.wikimedia.org/r/490478

Change 490478 merged by jenkins-bot:
[mediawiki/extensions/VisualEditor@master] Update VE core submodule to master (1d9e3a217)

https://gerrit.wikimedia.org/r/490478

ppelberg closed this task as Resolved.Mar 14 2019, 10:52 PM
ppelberg claimed this task.