Project

General

Profile

Actions

Defect #33639

closed

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

Added by Sergey Zapunidi almost 4 years ago. Updated almost 4 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Attachments
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed
Affected version:

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 LibreOffice is pasted as an image in addition to plain textClosedGo MAEDA

Actions
Actions #1

Updated by Go MAEDA almost 4 years 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
Actions #2

Updated by Go MAEDA almost 4 years 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++) {
Actions #3

Updated by Go MAEDA almost 4 years ago

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

Setting the target version to 4.1.2.

Actions #4

Updated by Takenori TAKAKI almost 4 years 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.

Actions #5

Updated by Go MAEDA almost 4 years 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.

Actions #6

Updated by Go MAEDA almost 4 years 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.

Actions #7

Updated by Go MAEDA almost 4 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF