Christian has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/70924


Change subject: Pasted content is annotated
......................................................................

Pasted content is annotated

Applying insertionAnnotations to pasted content.

Change-Id: I8f8a240ae8970624c34ae005290acc77cea73180
---
M modules/ve/ce/ve.ce.Surface.js
1 file changed, 23 insertions(+), 21 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor 
refs/changes/24/70924/1

diff --git a/modules/ve/ce/ve.ce.Surface.js b/modules/ve/ce/ve.ce.Surface.js
index 1517f73..00d869e 100644
--- a/modules/ve/ce/ve.ce.Surface.js
+++ b/modules/ve/ce/ve.ce.Surface.js
@@ -629,8 +629,8 @@
        scrollTop = $window.scrollTop();
        this.$pasteTarget.html( '' ).show().focus();
 
-       setTimeout( function () {
-               var pasteText, pasteData, tx,
+       setTimeout( ve.bind( function () {
+               var pasteData, slice, tx, annotations,
                        key = '';
 
                // Create key from text and element names
@@ -641,26 +641,28 @@
 
                // Get linear model from clipboard or create array from unknown 
pasted content
                if ( view.clipboard[key] ) {
-                       pasteData = view.clipboard[key];
+                       slice = view.clipboard[key];
                } else {
-                       pasteText = view.$pasteTarget.text().replace( /\n/gm, 
'' );
-                       pasteData = new ve.dm.DocumentSlice( ve.splitClusters( 
pasteText ) );
+                       slice = new ve.dm.DocumentSlice(
+                               ve.splitClusters(
+                                       view.$pasteTarget.text().replace( 
/\n/gm, '' )
+                               )
+                       );
+               }
+               pasteData = slice.getBalancedData();
+
+               // Annotate
+               annotations = this.model.getInsertionAnnotations();
+               if ( annotations instanceof ve.dm.AnnotationSet ) {
+                       ve.dm.Document.addAnnotationsToData( pasteData, 
this.model.getInsertionAnnotations() );
                }
 
-               // Transact
-               try {
-                       tx = ve.dm.Transaction.newFromInsertion(
-                               view.documentView.model,
-                               selection.start,
-                               pasteData.getData()
-                       );
-               } catch ( e ) {
-                       tx = ve.dm.Transaction.newFromInsertion(
-                               view.documentView.model,
-                               selection.start,
-                               pasteData.getBalancedData()
-                       );
-               }
+               // Transaction
+               tx = ve.dm.Transaction.newFromInsertion(
+                       view.documentView.model,
+                       selection.start,
+                       pasteData
+               );
 
                // Restore focus and scroll position
                view.documentView.documentNode.$.focus();
@@ -673,7 +675,7 @@
 
                // Allow pasting again
                view.pasting = false;
-       } );
+       }, this ) );
 };
 
 /**
@@ -1247,7 +1249,7 @@
        if ( !rangeToRemove.isCollapsed() ) {
                // If after processing removal transaction range is not 
collapsed it means that not
                // everything got merged nicely (at this moment transaction 
processor is capable of merging
-               // nodes of the same type and at the same depth level only), so 
we process with another 
+               // nodes of the same type and at the same depth level only), so 
we process with another
                // merging that takes remaing data from "endNode" and inserts 
it at the end of "startNode",
                // "endNode" or recrusivly its parent (if have only one child) 
gets removed.
                endNode = this.documentView.getNodeFromOffset( 
rangeToRemove.end, false );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8f8a240ae8970624c34ae005290acc77cea73180
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Christian <[email protected]>

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

Reply via email to