Vote #80930
完了Cannot paste image from clipboard when copying the image from web browsers or some apps
0%
説明
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.
journals
--------------------------------------------------------------------------------
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.
<pre><code class="diff">
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++) {
</pre></code>
--------------------------------------------------------------------------------
Setting the target version to 4.1.2.
--------------------------------------------------------------------------------
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.
--------------------------------------------------------------------------------
Committed the fix.
--------------------------------------------------------------------------------
Not only web browsers but some apps (at least Slack) are also affected.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
related_issues
relates,Closed,32469,Text copied from some applications such as MS Office and LibreOffice is pasted as an image in addition to plain text