jenkins-bot has submitted this change and it was merged.

Change subject: When pasting, try to use original range
......................................................................


When pasting, try to use original range

This functionality was (accidentally?) removed by I8f8a240a. It
stops us from over-zealously balancing data when we can get away
with just pasting the original selected range (e.g. it always wraps
collections of text and content nodes in another paragraph).

Bug: 53364
Change-Id: I93fa56c4e43083993c310e0050087e9d1de1e08b
---
M modules/ve/ce/ve.ce.Surface.js
1 file changed, 27 insertions(+), 9 deletions(-)

Approvals:
  Catrope: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/ve/ce/ve.ce.Surface.js b/modules/ve/ce/ve.ce.Surface.js
index f222756..58420f7 100644
--- a/modules/ve/ce/ve.ce.Surface.js
+++ b/modules/ve/ce/ve.ce.Surface.js
@@ -684,17 +684,35 @@
                                )
                        );
                }
-               pasteData = slice.getBalancedData();
 
-               // Annotate
-               ve.dm.Document.addAnnotationsToData( pasteData, 
this.model.getInsertionAnnotations() );
+               try {
+                       // Try to paste in the orignal data
+                       // Take a copy to prevent the data being annotated a 
second time in the catch block
+                       pasteData = ve.copy( slice.getData() );
 
-               // Transaction
-               tx = ve.dm.Transaction.newFromInsertion(
-                       view.documentView.model,
-                       selection.start,
-                       pasteData
-               );
+                       // Annotate
+                       ve.dm.Document.addAnnotationsToData( pasteData, 
this.model.getInsertionAnnotations() );
+
+                       // Transaction
+                       tx = ve.dm.Transaction.newFromInsertion(
+                               view.documentView.model,
+                               selection.start,
+                               pasteData
+                       );
+               } catch ( e ) {
+                       // If that fails, balance the data before pasting
+                       pasteData = slice.getBalancedData();
+
+                       // Annotate
+                       ve.dm.Document.addAnnotationsToData( pasteData, 
this.model.getInsertionAnnotations() );
+
+                       // Transaction
+                       tx = ve.dm.Transaction.newFromInsertion(
+                               view.documentView.model,
+                               selection.start,
+                               pasteData
+                       );
+               }
 
                // Restore focus and scroll position
                view.documentView.documentNode.$[0].focus();

-- 
To view, visit https://gerrit.wikimedia.org/r/81028
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I93fa56c4e43083993c310e0050087e9d1de1e08b
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Esanders <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to