Esanders has uploaded a new change for review.

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

Change subject: Correctly tag clipboard DM from MWTransclusionNodes
......................................................................

Correctly tag clipboard DM from MWTransclusionNodes

Iff in clipboard mode:
* Set data-ve-no-generated-contents on the main element
  regardless of whether we are using orignal DOM elements.
* Set data-ve-ignore on siblings, again, regardless or
  where they came from.

Bug: T89658

Change-Id: I82ad60f0b90e0c6ce88c42737bd36d1a289bcf34
---
M modules/ve-mw/dm/nodes/ve.dm.MWTransclusionNode.js
M modules/ve-mw/tests/dm/ve.dm.mwExample.js
2 files changed, 20 insertions(+), 21 deletions(-)


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

diff --git a/modules/ve-mw/dm/nodes/ve.dm.MWTransclusionNode.js 
b/modules/ve-mw/dm/nodes/ve.dm.MWTransclusionNode.js
index 0247908..3506bbe 100644
--- a/modules/ve-mw/dm/nodes/ve.dm.MWTransclusionNode.js
+++ b/modules/ve-mw/dm/nodes/ve.dm.MWTransclusionNode.js
@@ -111,29 +111,19 @@
                )
        ) {
                // The object in the store is also used for CE rendering so 
return a copy
-               return ve.copyDomElements( 
dataElement.attributes.originalDomElements, doc );
+               els = ve.copyDomElements( 
dataElement.attributes.originalDomElements, doc );
        } else {
                if ( dataElement.attributes.originalDomElements ) {
                        els = [ doc.createElement( 
dataElement.attributes.originalDomElements[0].nodeName ) ];
                } else {
                        els = [ doc.createElement( 'span' ) ];
                        if ( converter.isForClipboard() ) {
-                               // For the clipboard use the current DOM 
contents but mark as ignored
-                               // for the converter
+                               // For the clipboard use the current DOM 
contents so the user has something
+                               // meaningful to paste into external 
applications
                                currentDom = converter.getStore().value( index 
);
                                if ( currentDom ) {
-                                       currentDom = ve.copyDomElements( 
currentDom, doc );
-                                       // i = 0 is the data-mw span
-                                       for ( i = 1, len = currentDom.length; i 
< len; i++ ) {
-                                               // Wrap plain text nodes so we 
can give them an attribute
-                                               if ( currentDom[i].nodeType === 
Node.TEXT_NODE ) {
-                                                       wrapper = 
doc.createElement( 'span' );
-                                                       wrapper.appendChild( 
currentDom[i] );
-                                                       currentDom[i] = wrapper;
-                                               }
-                                               currentDom[i].setAttribute( 
'data-ve-ignore', 'true' );
-                                               els.push( currentDom[i] );
-                                       }
+                                       // Ignore currentDom[0] as that is the 
data-mw span we are recreating
+                                       els = els.concat( ve.copyDomElements( 
currentDom.slice( 1 ), doc ) );
                                }
                        }
                }
@@ -141,13 +131,24 @@
                // reconstructed data-mw property.
                els[0].setAttribute( 'typeof', 'mw:Transclusion' );
                els[0].setAttribute( 'data-mw', JSON.stringify( 
dataElement.attributes.mw ) );
-               // Mark the element as not having valid generated contents with 
it in case it is
+       }
+       if ( converter.isForClipboard() ) {
+               // Mark the data-mw element as not having valid generated 
contents with it in case it is
                // inserted into another editor (e.g. via paste).
                els[0].setAttribute( 'data-ve-no-generated-contents', true );
-               // TODO: Include last-known generated contents in the output 
for rich
-               // paste into a non-VE editor
-               return els;
+
+               // ... and mark all but the first child as ignorable
+               for ( i = 1, len = els.length; i < len; i++ ) {
+                       // Wrap plain text nodes so we can give them an 
attribute
+                       if ( els[i].nodeType === Node.TEXT_NODE ) {
+                               wrapper = doc.createElement( 'span' );
+                               wrapper.appendChild( els[i] );
+                               els[i] = wrapper;
+                       }
+                       els[i].setAttribute( 'data-ve-ignore', 'true' );
+               }
        }
+       return els;
 };
 
 /**
diff --git a/modules/ve-mw/tests/dm/ve.dm.mwExample.js 
b/modules/ve-mw/tests/dm/ve.dm.mwExample.js
index 2511d5e..5e6b093 100644
--- a/modules/ve-mw/tests/dm/ve.dm.mwExample.js
+++ b/modules/ve-mw/tests/dm/ve.dm.mwExample.js
@@ -25,7 +25,6 @@
        blockOpenModified:
                '<div about="#mwt1" typeof="mw:Transclusion"' +
                        ' 
data-mw="{&quot;parts&quot;:[{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;Test&quot;,&quot;href&quot;:&quot;./Template:Test&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;Hello,
 globe!&quot;}},&quot;i&quot;:0}}]}"' +
-                       ' data-ve-no-generated-contents="true"' +
                '>' +
                '</div>',
        blockContent: '<p about="#mwt1" data-parsoid="{}">Hello, world!</p>',
@@ -36,7 +35,6 @@
        inlineOpenModified:
                '<span about="#mwt1" typeof="mw:Transclusion"' +
                        ' 
data-mw="{&quot;parts&quot;:[{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;Inline&quot;,&quot;href&quot;:&quot;./Template:Inline&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;5,678&quot;}},&quot;i&quot;:0}}]}"'
 +
-                       ' data-ve-no-generated-contents="true"' +
                '>',
        inlineContent: '$1,234.00',
        inlineClose: '</span>',

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

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

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

Reply via email to