[MediaWiki-commits] [Gerrit] VisualEditor/VisualEditor[master]: Make keepEmptyContentBranches an option of #sanitize and sim...

2016-08-05 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Make keepEmptyContentBranches an option of #sanitize and 
simplify usage
..


Make keepEmptyContentBranches an option of #sanitize and simplify usage

Change-Id: I62b6897050c4257ce23f3420627016bea306e245
---
M src/ce/ve.ce.Surface.js
M src/dm/lineardata/ve.dm.ElementLinearData.js
M src/dm/ve.dm.Document.js
3 files changed, 12 insertions(+), 16 deletions(-)

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



diff --git a/src/ce/ve.ce.Surface.js b/src/ce/ve.ce.Surface.js
index 8856e2d..1150a94 100644
--- a/src/ce/ve.ce.Surface.js
+++ b/src/ce/ve.ce.Surface.js
@@ -1872,7 +1872,7 @@
tableAction,
items = [],
importantElement = '[id],[typeof],[rel]',
-   importRules = !this.pasteSpecial ? 
this.getSurface().getImportRules() : { all: { plainText: true } },
+   importRules = !this.pasteSpecial ? 
this.getSurface().getImportRules() : { all: { plainText: true, 
keepEmptyContentBranches: true } },
beforePasteData = this.beforePasteData || {},
surfaceModel = this.getModel(),
fragment = surfaceModel.getFragment(),
@@ -1880,12 +1880,12 @@
documentModel = surfaceModel.getDocument(),
view = this;
 
-   function sanitize( linearData, keepEmptyContentBranches ) {
+   function sanitize( linearData ) {
// If the clipboardKey isn't set (paste from non-VE instance) 
use external import rules
if ( !clipboardKey ) {
-   linearData.sanitize( importRules.external || {}, 
keepEmptyContentBranches );
+   linearData.sanitize( importRules.external || {} );
}
-   linearData.sanitize( importRules.all || {}, 
keepEmptyContentBranches );
+   linearData.sanitize( importRules.all || {} );
}
 
// If the selection doesn't collapse after paste then nothing was 
inserted
@@ -2011,7 +2011,7 @@
);
 
if ( this.pasteSpecial ) {
-   sanitize( pasteData, true );
+   sanitize( pasteData );
}
 
// Insert content
@@ -2025,7 +2025,7 @@
);
 
if ( this.pasteSpecial ) {
-   sanitize( pasteData, true );
+   sanitize( pasteData );
}
 
// Insert content
@@ -2129,10 +2129,8 @@
pastedDocumentModel.getStore(),
ve.copy( beforePasteData.context )
);
-   if ( this.pasteSpecial ) {
-   // The context may have been sanitized, so 
sanitize here as well for comparison
-   sanitize( context, true );
-   }
+   // Sanitize context to match data
+   sanitize( context );
 
// Remove matching context from the left
left = 0;
diff --git a/src/dm/lineardata/ve.dm.ElementLinearData.js 
b/src/dm/lineardata/ve.dm.ElementLinearData.js
index d687070..3d3cce2 100644
--- a/src/dm/lineardata/ve.dm.ElementLinearData.js
+++ b/src/dm/lineardata/ve.dm.ElementLinearData.js
@@ -1021,9 +1021,9 @@
  * @param {boolean} [rules.allowBreaks] Allow  line breaks, otherwise the 
node will be split
  * @param {boolean} [rules.preserveHtmlWhitespace] Preserve non-semantic HTML 
whitespace
  * @param {boolean} [rules.nodeSanitization] Apply per-type node sanitizations 
via ve.dm.Node#sanitize
- * @param {boolean} [keepEmptyContentBranches=false] Preserve empty content 
branch nodes
+ * @param {boolean} [rules.keepEmptyContentBranches] Preserve empty content 
branch nodes
  */
-ve.dm.ElementLinearData.prototype.sanitize = function ( rules, 
keepEmptyContentBranches ) {
+ve.dm.ElementLinearData.prototype.sanitize = function ( rules ) {
var i, len, annotations, emptySet, setToRemove, type,
canContainContent, contentElement, isOpen, nodeClass, ann, 
oldHash,
store = this.getStore(),
@@ -1098,7 +1098,7 @@
 
// If a node is empty but can contain content, then 
just remove it
if (
-   !keepEmptyContentBranches &&
+   !rules.keepEmptyContentBranches &&
i > 0 && !isOpen && this.isOpenElementData( i - 
1 ) &&
canContainContent
) {
diff --git a/src/dm/ve.dm.Document.js b/src/dm/ve.dm.Document.js
index 0e7201f..bc6b3a8 100644
--- a/src/dm/ve.dm.Document.js
+++ 

[MediaWiki-commits] [Gerrit] VisualEditor/VisualEditor[master]: Make keepEmptyContentBranches an option of #sanitize and sim...

2016-08-01 Thread Esanders (Code Review)
Esanders has uploaded a new change for review.

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

Change subject: Make keepEmptyContentBranches an option of #sanitize and 
simplify usage
..

Make keepEmptyContentBranches an option of #sanitize and simplify usage

Change-Id: I62b6897050c4257ce23f3420627016bea306e245
---
M src/ce/ve.ce.Surface.js
M src/dm/lineardata/ve.dm.ElementLinearData.js
M src/dm/ve.dm.Document.js
3 files changed, 12 insertions(+), 16 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor 
refs/changes/56/302256/1

diff --git a/src/ce/ve.ce.Surface.js b/src/ce/ve.ce.Surface.js
index dca130a..7814d7a 100644
--- a/src/ce/ve.ce.Surface.js
+++ b/src/ce/ve.ce.Surface.js
@@ -1870,7 +1870,7 @@
tableAction,
items = [],
importantElement = '[id],[typeof],[rel]',
-   importRules = !this.pasteSpecial ? 
this.getSurface().getImportRules() : { all: { plainText: true } },
+   importRules = !this.pasteSpecial ? 
this.getSurface().getImportRules() : { all: { plainText: true, 
keepEmptyContentBranches: true } },
beforePasteData = this.beforePasteData || {},
surfaceModel = this.getModel(),
fragment = surfaceModel.getFragment(),
@@ -1878,12 +1878,12 @@
documentModel = surfaceModel.getDocument(),
view = this;
 
-   function sanitize( linearData, keepEmptyContentBranches ) {
+   function sanitize( linearData ) {
// If the clipboardKey isn't set (paste from non-VE instance) 
use external import rules
if ( !clipboardKey ) {
-   linearData.sanitize( importRules.external || {}, 
keepEmptyContentBranches );
+   linearData.sanitize( importRules.external || {} );
}
-   linearData.sanitize( importRules.all || {}, 
keepEmptyContentBranches );
+   linearData.sanitize( importRules.all || {} );
}
 
// If the selection doesn't collapse after paste then nothing was 
inserted
@@ -2009,7 +2009,7 @@
);
 
if ( this.pasteSpecial ) {
-   sanitize( pasteData, true );
+   sanitize( pasteData );
}
 
// Insert content
@@ -2023,7 +2023,7 @@
);
 
if ( this.pasteSpecial ) {
-   sanitize( pasteData, true );
+   sanitize( pasteData );
}
 
// Insert content
@@ -2127,10 +2127,8 @@
pastedDocumentModel.getStore(),
ve.copy( beforePasteData.context )
);
-   if ( this.pasteSpecial ) {
-   // The context may have been sanitized, so 
sanitize here as well for comparison
-   sanitize( context, true );
-   }
+   // Sanitize context to match data
+   sanitize( context );
 
// Remove matching context from the left
left = 0;
diff --git a/src/dm/lineardata/ve.dm.ElementLinearData.js 
b/src/dm/lineardata/ve.dm.ElementLinearData.js
index d687070..3d3cce2 100644
--- a/src/dm/lineardata/ve.dm.ElementLinearData.js
+++ b/src/dm/lineardata/ve.dm.ElementLinearData.js
@@ -1021,9 +1021,9 @@
  * @param {boolean} [rules.allowBreaks] Allow  line breaks, otherwise the 
node will be split
  * @param {boolean} [rules.preserveHtmlWhitespace] Preserve non-semantic HTML 
whitespace
  * @param {boolean} [rules.nodeSanitization] Apply per-type node sanitizations 
via ve.dm.Node#sanitize
- * @param {boolean} [keepEmptyContentBranches=false] Preserve empty content 
branch nodes
+ * @param {boolean} [rules.keepEmptyContentBranches] Preserve empty content 
branch nodes
  */
-ve.dm.ElementLinearData.prototype.sanitize = function ( rules, 
keepEmptyContentBranches ) {
+ve.dm.ElementLinearData.prototype.sanitize = function ( rules ) {
var i, len, annotations, emptySet, setToRemove, type,
canContainContent, contentElement, isOpen, nodeClass, ann, 
oldHash,
store = this.getStore(),
@@ -1098,7 +1098,7 @@
 
// If a node is empty but can contain content, then 
just remove it
if (
-   !keepEmptyContentBranches &&
+   !rules.keepEmptyContentBranches &&
i > 0 && !isOpen && this.isOpenElementData( i - 
1 ) &&
canContainContent
) {
diff --git a/src/dm/ve.dm.Document.js b/src/dm/ve.dm.Document.js
index 0e7201f..bc6b3a8 100644