プロジェクト

全般

プロフィール

Vote #80930

完了

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

Admin Redmine さんが約4年前に追加. 約4年前に更新.

ステータス:
Closed
優先度:
通常
担当者:
-
カテゴリ:
Attachments_19
対象バージョン:
開始日:
2022/05/09
期日:
進捗率:

0%

予定工数:
category_id:
19
version_id:
162
issue_org_id:
33639
author_id:
406125
assigned_to_id:
332
comments:
7
status_id:
5
tracker_id:
1
plus1:
0
affected_version:
closed_on:
affected_version_id:
127
ステータス-->[Closed]

説明

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

Admin Redmine さんが約4年前に更新

  • カテゴリAttachments_19 にセット
  • 対象バージョン4.1.2_162 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0