Defect #32469

Text copied from some applications such as MS Office and LibreOffice is pasted as an image in addition to plain text

Added by Takenori TAKAKI 2 months ago. Updated about 1 month ago.

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

0%

Category:UI
Target version:-
Resolution:Fixed Affected version:

Description

When copying text from an Office product (e.g. MS Office, LibreOffice) and pasting it on redmine,
The image is pasted after the text. as shown below.

In this case, Clipboard contains multiple data (text and image), so both are pasted(attached) from clipboard.

To solve this problem, I propose the following change.
(Does not execute JS function ’copyImageFromClipboard’, if Clipboard contains text data)

index b856ff415..4a33daf55 100644
--- a/public/javascripts/attachments.js
+++ b/public/javascripts/attachments.js
@@ -255,6 +255,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(t => /^text/.test(t))) { return; }

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

duplicate-pasting.png (81.9 KB) Takenori TAKAKI, 2019-11-13 16:07

duplicate-pasting.png (81.8 KB) Takenori TAKAKI, 2019-11-13 16:19


Related issues

Related to Redmine - Feature #3816: Allow pasting screenshots from clipboard Closed 2009-09-03

Associated revisions

Revision 19089
Added by Go MAEDA 2 months ago

Fix that text copied from some applications such as MS Office and LibreOffice is pasted as an image in addition to plain text (#32469, #3816).

Patch by Takenori TAKAKI.

Revision 19090
Added by Go MAEDA 2 months ago

Merged r19089 from trunk to 4.1-stable (#32469, #3816).

Revision 19371
Added by Go MAEDA about 1 month ago

Fixes not to use arrow function not supported by Internet Explorer (#32469, #3816).

Patch by Takenori TAKAKI.

Revision 19372
Added by Go MAEDA about 1 month ago

Merged r19371 from trunk to 4.1-stable (#32469, #3816).

History

#1 Updated by Takenori TAKAKI 2 months ago

#2 Updated by Go MAEDA 2 months ago

  • Related to Feature #3816: Allow pasting screenshots from clipboard added

#3 Updated by Jean-Philippe Lang 2 months ago

  • Target version set to 4.1.0

#4 Updated by Marius BALTEANU 2 months ago

The fix looks good to me.

#5 Updated by Go MAEDA 2 months ago

  • Subject changed from Duplicate pasting ("text" and "imaged text"). When copy and paste text from Office product (e.g. MS Office, LibreOffice). to Text copied from some applications such as MS Office and LibreOffice are pasted as an image in addition to plain text

#6 Updated by Go MAEDA 2 months ago

  • Subject changed from Text copied from some applications such as MS Office and LibreOffice are pasted as an image in addition to plain text to Text copied from some applications such as MS Office and LibreOffice is pasted as an image in addition to plain text
  • Status changed from New to Closed
  • Assignee set to Go MAEDA
  • Target version deleted (4.1.0)
  • Resolution set to Fixed

Committed the patch as a part of #3816. Thank you for fixing the issue.

#7 Updated by Takenori TAKAKI about 1 month ago

  • Status changed from Closed to Reopened

Arrow function (=>) is not supported in IE, so my patch had a problem that an error was output to the browser console.
Therefore, reopen the ticket and write the improvement code below.

index 4a33daf55..af50cd8ba 100644
--- a/public/javascripts/attachments.js
+++ b/public/javascripts/attachments.js
@@ -255,7 +255,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(t => /^text/.test(t))) { return; }
+  if (clipboardData.types.some(function(t){ return /^text/.test(t); })) { return; }

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

#8 Updated by Go MAEDA about 1 month ago

  • Status changed from Reopened to Closed

Takenori TAKAKI wrote:

Arrow function (=>) is not supported in IE, so my patch had a problem that an error was output to the browser console.

Committed the fix in r19371. Thank you.

Also available in: Atom PDF