Defect #33639

Cannot paste image from clipboard when copying the image from web browsers or some apps

Added by Sergey Zapunidi 4 months ago. Updated 4 months ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Go MAEDA% Done:

0%

Category:Attachments
Target version:4.1.2
Resolution:Fixed Affected version:4.1.0

Description

Redmine 4.1.0 gained embedded feature to automatically upload and embed images from clipboard. This works fine unless both text format and image format is present in the clipboard. Unfortunately it's how browsers (Firefox, Chrome) populate clipboard buffer when you copy an image.
To reproduce the problem take Firefox or Chrome browser and right button click on the image and select Copy image. Then open an issue in Redmine, put cursor in the text area, and Paste from clipboard. nothing will happen, while uploading image is expected.
How to fix: go to a clipboard editor (I used CopyQ), you will see image/png and text/html formats. Delete the text/html part. Now redmine will accept image from clipboard.
Another indirect approach is to pasting image to gimp and recopying it again from there to clipboard (text part will drop on the way)

The problem lies within JS function copyImageFromClipboard(e).

function copyImageFromClipboard(e) {
  if (!$(e.target).hasClass('wiki-edit')) { return; }
  var clipboardData = e.clipboardData || e.originalEvent.clipboardData
  if (!clipboardData) { return; }
  if (clipboardData.types.some(function(t){ return /^text/.test(t); })) { return; }
...
}

The last cited line finds text part and returns from function. I am not that far familiar with redmine to suggest a patch, but other applications have no problem pasting images copyed from a browser. So there is a way to detect the nature of clipboard contents.


Related issues

Related to Redmine - Defect #32469: Text copied from some applications such as MS Office and ... Closed

Associated revisions

Revision 19834
Added by Go MAEDA 4 months ago

Cannot paste image from clipboard when copying the image from web browsers or some apps (#33639).

Patch by Go MAEDA.

Revision 19835
Added by Go MAEDA 4 months ago

Merged r19834 from trunk to 4.1-stable (#33639).

History

#1 Updated by Go MAEDA 4 months ago

  • Related to Defect #32469: Text copied from some applications such as MS Office and LibreOffice is pasted as an image in addition to plain text added

#2 Updated by Go MAEDA 4 months ago

  • Category changed from Issues to Attachments
  • Status changed from New to Confirmed
  • Target version set to Candidate for next minor release

Thank you for reporting the issue.

Sergey Zapunidi wrote:

The problem lies within JS function copyImageFromClipboard(e).
[...]
The last cited line finds text part and returns from function.

The purpose of the code is to prevent attaching an unnecessary image when you paste text from Microsoft Office of LibreOffice (see #32469 for details).

I found that changing the code as follows fixes the issue that images copied from web browsers are not pasted.

diff --git a/public/javascripts/attachments.js b/public/javascripts/attachments.js
index 01cf5cc15..25f318852 100644
--- a/public/javascripts/attachments.js
+++ b/public/javascripts/attachments.js
@@ -258,7 +258,7 @@ function copyImageFromClipboard(e) {
   if (!$(e.target).hasClass('wiki-edit')) { return; }
   var clipboardData = e.clipboardData || e.originalEvent.clipboardData
   if (!clipboardData) { return; }
-  if (clipboardData.types.some(function(t){ return /^text/.test(t); })) { return; }
+  if (clipboardData.types.some(function(t){ return /^text\/plain$/.test(t); })) { return; }

   var items = clipboardData.items
   for (var i = 0 ; i < items.length ; i++) {

#3 Updated by Go MAEDA 4 months ago

  • Target version changed from Candidate for next minor release to 4.1.2

Setting the target version to 4.1.2.

#4 Updated by Takenori TAKAKI 4 months ago

Thank you for reporting the bug and suggesting improvements.
The patch proposed by Go Maeda worked fine as expected on the browser (Firefox and Chrome) that was reported.
Improvement on #32469 seem to work fine as well.

#5 Updated by Go MAEDA 4 months ago

  • Subject changed from Can't automatically upload image from clipboard when copying image from a browser to Cannot paste an image from clipboard when copying from a web browser
  • Status changed from Confirmed to Resolved
  • Assignee set to Go MAEDA
  • Resolution set to Fixed

Committed the fix.

#6 Updated by Go MAEDA 4 months ago

  • Subject changed from Cannot paste an image from clipboard when copying from a web browser to Cannot paste image from clipboard when copying the image from web browsers or some apps

Not only web browsers but some apps (at least Slack) are also affected.

#7 Updated by Go MAEDA 4 months ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF