Catrope has uploaded a new change for review.

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


Change subject: Allow hybrids across Model subclasses
......................................................................

Allow hybrids across Model subclasses

A node could already implement a toDataElements() function that
returns a data element of another node type, but it couldn't return
an annotation or a meta item. This is fixed now, and any dm.Model
subclass can now morph into any other dm.Model subclass.

I didn't originally plan to do this today at all, but doing this now
makes my upcoming converter changes easier. Surprise feature!

Change-Id: Ief6ac302094df084221a5a97c32a522b929c2960
---
M modules/ve/dm/ve.dm.Converter.js
1 file changed, 14 insertions(+), 9 deletions(-)


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

diff --git a/modules/ve/dm/ve.dm.Converter.js b/modules/ve/dm/ve.dm.Converter.js
index 583865f..7210117 100644
--- a/modules/ve/dm/ve.dm.Converter.js
+++ b/modules/ve/dm/ve.dm.Converter.js
@@ -370,7 +370,7 @@
 
        var i, childDomElement, childDomElements, childDataElement, text, 
childTypes, matches,
                wrappingParagraph, prevElement, childAnnotations, modelName, 
modelClass,
-               annotation, annotationData, childIsContent, aboutGroup,
+               annotation, childIsContent, aboutGroup,
                data = [],
                nextWhitespace = '',
                wrappedWhitespace = '',
@@ -403,10 +403,20 @@
                                modelName = this.modelRegistry.matchElement( 
childDomElement );
                                modelClass = this.modelRegistry.lookup( 
modelName ) || ve.dm.AlienNode;
                                if ( modelClass.prototype instanceof 
ve.dm.Annotation ) {
-                                       annotationData = 
this.createDataElement( modelClass, [ childDomElement ] );
+                                       childDataElement = 
this.createDataElement( modelClass, [ childDomElement ] );
+                               } else {
+                                       // Node or meta item
+                                       aboutGroup = getAboutGroup( 
childDomElement );
+                                       childDomElements = 
modelClass.static.enableAboutGrouping ?
+                                               aboutGroup : [ childDomElement 
];
+                                       childDataElement = 
this.createDataElement( modelClass, childDomElements );
                                }
-                               if ( modelClass.prototype instanceof 
ve.dm.Annotation && annotationData ) {
-                                       annotation = 
this.annotationFactory.create( modelName, annotationData );
+
+                               // Update modelClass to reflect the type we got 
back
+                               modelClass = this.modelRegistry.lookup( 
childDataElement.type );
+                               // Now take the appropriate action based on that
+                               if ( modelClass.prototype instanceof 
ve.dm.Annotation ) {
+                                       annotation = 
this.annotationFactory.create( modelName, childDataElement );
                                        // Start wrapping if needed
                                        if ( !context.inWrapper && 
!context.expectingContent ) {
                                                startWrapping();
@@ -420,11 +430,6 @@
                                        );
                                } else {
                                        // Node or meta item
-                                       aboutGroup = getAboutGroup( 
childDomElement );
-                                       childDomElements = 
modelClass.static.enableAboutGrouping ?
-                                               aboutGroup : [ childDomElement 
];
-                                       childDataElement = 
this.createDataElement( modelClass, childDomElements );
-
                                        if ( modelClass.prototype instanceof 
ve.dm.MetaItem ) {
                                                // No additional processing 
needed
                                                // Write to data and continue

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

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

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

Reply via email to