From a496d4aa42515ecedca12724feec02a56de2688b Mon Sep 17 00:00:00 2001 From: epriestley Date: Sat, 21 Jun 2014 10:04:46 -0700 Subject: [PATCH] When pasting both image data and text into Chrome, use only the text Summary: Fixes T5437. This actual behavior is debateable but this is the one that seems simplest and most sensible. Test Plan: Copied some cells from Numbers, pasted them into a remarkup box in Chrome, got just the text. Reviewers: btrahan, chad Reviewed By: chad Subscribers: epriestley Maniphest Tasks: T5437 Differential Revision: https://secure.phabricator.com/D9647 --- resources/celerity/map.php | 24 +++++++++---------- webroot/rsrc/js/core/DragAndDropFileUpload.js | 21 ++++++++++++---- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/resources/celerity/map.php b/resources/celerity/map.php index f90fc3562c..eed28a0957 100644 --- a/resources/celerity/map.php +++ b/resources/celerity/map.php @@ -11,7 +11,7 @@ return array( 'core.pkg.js' => '07b01d4f', 'darkconsole.pkg.js' => 'ca8671ce', 'differential.pkg.css' => '4a93db37', - 'differential.pkg.js' => '2b128f3a', + 'differential.pkg.js' => '5b252007', 'diffusion.pkg.css' => '471bc9eb', 'diffusion.pkg.js' => '077e3ad0', 'maniphest.pkg.css' => 'f88a8402', @@ -434,7 +434,7 @@ return array( 'rsrc/js/application/uiexample/gesture-example.js' => 'f42bb8c6', 'rsrc/js/application/uiexample/notification-example.js' => 'c51a6616', 'rsrc/js/core/Busy.js' => '6453c869', - 'rsrc/js/core/DragAndDropFileUpload.js' => 'ae6abfba', + 'rsrc/js/core/DragAndDropFileUpload.js' => '1d8ad5c3', 'rsrc/js/core/DraggableList.js' => '109e2a87', 'rsrc/js/core/FileUpload.js' => 'a4ae61bf', 'rsrc/js/core/Hovercard.js' => '4f344388', @@ -708,7 +708,7 @@ return array( 'phabricator-countdown-css' => '86b7b0a0', 'phabricator-crumbs-view-css' => '7fbf25b8', 'phabricator-dashboard-css' => '22dfc441', - 'phabricator-drag-and-drop-file-upload' => 'ae6abfba', + 'phabricator-drag-and-drop-file-upload' => '1d8ad5c3', 'phabricator-draggable-list' => '109e2a87', 'phabricator-fatal-config-template-css' => '25d446d6', 'phabricator-feed-css' => '5cbec787', @@ -970,6 +970,15 @@ return array( 1 => 'javelin-util', 2 => 'phabricator-keyboard-shortcut-manager', ), + '1d8ad5c3' => + array( + 0 => 'javelin-install', + 1 => 'javelin-util', + 2 => 'javelin-request', + 3 => 'javelin-dom', + 4 => 'javelin-uri', + 5 => 'phabricator-file-upload', + ), '1da67f34' => array( 0 => 'javelin-behavior', @@ -1656,15 +1665,6 @@ return array( 3 => 'javelin-dom', 4 => 'javelin-vector', ), - 'ae6abfba' => - array( - 0 => 'javelin-install', - 1 => 'javelin-util', - 2 => 'javelin-request', - 3 => 'javelin-dom', - 4 => 'javelin-uri', - 5 => 'phabricator-file-upload', - ), 'b3a4b884' => array( 0 => 'javelin-behavior', diff --git a/webroot/rsrc/js/core/DragAndDropFileUpload.js b/webroot/rsrc/js/core/DragAndDropFileUpload.js index 25c6c1a723..efe7a06dca 100644 --- a/webroot/rsrc/js/core/DragAndDropFileUpload.js +++ b/webroot/rsrc/js/core/DragAndDropFileUpload.js @@ -121,13 +121,26 @@ JX.install('PhabricatorDragAndDropFileUpload', { 'paste', null, JX.bind(this, function(e) { - var clipboardData = e.getRawEvent().clipboardData; - if (!clipboardData) { + var clipboard = e.getRawEvent().clipboardData; + if (!clipboard) { return; } - for (var ii = 0; ii < clipboardData.items.length; ii++) { - var item = clipboardData.items[ii]; + // If there's any text on the clipboard, just let the event fire + // normally, choosing the text over any images. See T5437 / D9647. + var text = clipboard.getData('text/plain').toString(); + if (text.length) { + return; + } + + // Safari and Firefox have clipboardData, but no items. They + // don't seem to provide a way to get image data directly yet. + if (!clipboard.items) { + return; + } + + for (var ii = 0; ii < clipboard.items.length; ii++) { + var item = clipboard.items[ii]; if (!/^image\//.test(item.type)) { continue; }