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

Change subject: wrapAllNodes in sourcefragment
......................................................................


wrapAllNodes in sourcefragment

Change-Id: I1014ee30dc1000a4515e2daacbfd591f15f3ce13
---
M src/dm/ve.dm.SourceSurfaceFragment.js
1 file changed, 50 insertions(+), 0 deletions(-)

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



diff --git a/src/dm/ve.dm.SourceSurfaceFragment.js 
b/src/dm/ve.dm.SourceSurfaceFragment.js
index 0a817c6..bc8a5af 100644
--- a/src/dm/ve.dm.SourceSurfaceFragment.js
+++ b/src/dm/ve.dm.SourceSurfaceFragment.js
@@ -106,6 +106,56 @@
 };
 
 /**
+ * @inheritdoc
+ */
+ve.dm.SourceSurfaceFragment.prototype.wrapAllNodes = function ( wrapOuter, 
wrapEach ) {
+       var i, node, nodes,
+               content,
+               range = this.getSelection().getCoveringRange();
+
+       if ( !range ) {
+               return this;
+       }
+
+       function getOpening( element ) {
+               element.internal = {
+                       whitespace: [ '\n', '\n', '\n', '\n' ]
+               };
+               return element;
+       }
+
+       function getClosing( element ) {
+               return { type: '/' + element.type };
+       }
+
+       if ( !Array.isArray( wrapOuter ) ) {
+               wrapOuter = [ wrapOuter ];
+       }
+
+       wrapEach = wrapEach || [];
+
+       if ( !Array.isArray( wrapEach ) ) {
+               wrapEach = [ wrapEach ];
+       }
+
+       nodes = this.getSelectedLeafNodes();
+
+       content = wrapOuter.map( getOpening );
+       for ( i = 0; i < nodes.length; i++ ) {
+               node = nodes[ i ];
+               content = content
+                       .concat( wrapEach.map( getOpening ) )
+                       .concat( this.getSurface().getLinearFragment( 
node.getRange() ).getText().split( '' ) )
+                       .concat( wrapEach.reverse().map( getClosing ) );
+       }
+       content = content.concat( wrapOuter.reverse().map( getClosing ) );
+
+       this.insertContent( content );
+
+       return this;
+};
+
+/**
  * Convert sub document to source text
  *
  * The default implementation converts to HTML synchronously.

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I1014ee30dc1000a4515e2daacbfd591f15f3ce13
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <esand...@wikimedia.org>
Gerrit-Reviewer: Jforrester <jforres...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to