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

Change subject: Sections: Make sections & articles un-unwrappable
......................................................................


Sections: Make sections & articles un-unwrappable

Introduces ve.Node#isUnwrappable and removes existing hacks
that hard code checks for textNode/tableCellNode.

Bug: T131659
Change-Id: I76570eedbbd5a0d0338508432e1a323721d48810
---
M src/ce/keydownhandlers/ve.ce.LinearDeleteKeyDownHandler.js
M src/ce/ve.ce.Node.js
M src/dm/nodes/ve.dm.ArticleNode.js
M src/dm/nodes/ve.dm.SectionNode.js
M src/dm/nodes/ve.dm.TableCellNode.js
M src/dm/ve.dm.Node.js
M src/dm/ve.dm.NodeFactory.js
M src/ve.Node.js
8 files changed, 57 insertions(+), 3 deletions(-)

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



diff --git a/src/ce/keydownhandlers/ve.ce.LinearDeleteKeyDownHandler.js 
b/src/ce/keydownhandlers/ve.ce.LinearDeleteKeyDownHandler.js
index 168ddda..7d2fdca 100644
--- a/src/ce/keydownhandlers/ve.ce.LinearDeleteKeyDownHandler.js
+++ b/src/ce/keydownhandlers/ve.ce.LinearDeleteKeyDownHandler.js
@@ -228,9 +228,8 @@
                        startNode = 
documentModel.getDocumentNode().getNodeFromOffset( offset - 1 );
                        nodeRange = startNode.getOuterRange();
                        if (
-                               // regular text (e.g. "<p>foo|</p>")
-                               ( startNode.getType() === 'text' ) ||
-                               ( startNode.getType() === 'tableCell' ) ||
+                               // The node is not unwrappable (e.g. table 
cells, text nodes)
+                               !startNode.isUnwrappable() ||
                                // content item at the start / end?
                                (
                                        ( startNode.canContainContent() || 
documentModel.getDocumentNode() === startNode ) &&
diff --git a/src/ce/ve.ce.Node.js b/src/ce/ve.ce.Node.js
index 3f256e3..78bb798 100644
--- a/src/ce/ve.ce.Node.js
+++ b/src/ce/ve.ce.Node.js
@@ -116,6 +116,13 @@
 /**
  * @inheritdoc ve.Node
  */
+ve.ce.Node.prototype.isUnwrappable = function () {
+       return this.model.isUnwrappable();
+};
+
+/**
+ * @inheritdoc ve.Node
+ */
 ve.ce.Node.prototype.canContainContent = function () {
        return this.model.canContainContent();
 };
diff --git a/src/dm/nodes/ve.dm.ArticleNode.js 
b/src/dm/nodes/ve.dm.ArticleNode.js
index 9e2a19b..882b5de 100644
--- a/src/dm/nodes/ve.dm.ArticleNode.js
+++ b/src/dm/nodes/ve.dm.ArticleNode.js
@@ -27,6 +27,8 @@
 
 ve.dm.ArticleNode.static.name = 'article';
 
+ve.dm.ArticleNode.static.isUnwrappable = false;
+
 ve.dm.ArticleNode.static.matchTagNames = [ 'article' ];
 
 /* Methods */
diff --git a/src/dm/nodes/ve.dm.SectionNode.js 
b/src/dm/nodes/ve.dm.SectionNode.js
index 3dd7d96..487db96 100644
--- a/src/dm/nodes/ve.dm.SectionNode.js
+++ b/src/dm/nodes/ve.dm.SectionNode.js
@@ -27,6 +27,8 @@
 
 ve.dm.SectionNode.static.name = 'section';
 
+ve.dm.SectionNode.static.isUnwrappable = false;
+
 ve.dm.SectionNode.static.defaultAttributes = {
        style: 'section'
 };
diff --git a/src/dm/nodes/ve.dm.TableCellNode.js 
b/src/dm/nodes/ve.dm.TableCellNode.js
index 51c5753..289bad1 100644
--- a/src/dm/nodes/ve.dm.TableCellNode.js
+++ b/src/dm/nodes/ve.dm.TableCellNode.js
@@ -33,6 +33,8 @@
 
 ve.dm.TableCellNode.static.name = 'tableCell';
 
+ve.dm.TableCellNode.static.isUnwrappable = false;
+
 ve.dm.TableCellNode.static.parentNodeTypes = [ 'tableRow' ];
 
 ve.dm.TableCellNode.static.defaultAttributes = { style: 'data' };
diff --git a/src/dm/ve.dm.Node.js b/src/dm/ve.dm.Node.js
index 4c59bf5..bd72669 100644
--- a/src/dm/ve.dm.Node.js
+++ b/src/dm/ve.dm.Node.js
@@ -109,6 +109,15 @@
 ve.dm.Node.static.isWrapped = true;
 
 /**
+ * Whether this node type can be unwrapped by user input (e.g. backspace to 
unwrap a list item)
+ *
+ * @static
+ * @property {boolean}
+ * @inheritable
+ */
+ve.dm.Node.static.isUnwrappable = true;
+
+/**
  * Whether this node type is a content node type. This means the node 
represents content, cannot
  * have children, and can only appear as children of a content container node. 
Content nodes are
  * also known as inline nodes.
@@ -401,6 +410,13 @@
 /**
  * @inheritdoc ve.Node
  */
+ve.dm.Node.prototype.isUnwrappable = function () {
+       return this.isWrapped() && this.constructor.static.isUnwrappable;
+};
+
+/**
+ * @inheritdoc ve.Node
+ */
 ve.dm.Node.prototype.canContainContent = function () {
        return this.constructor.static.canContainContent;
 };
diff --git a/src/dm/ve.dm.NodeFactory.js b/src/dm/ve.dm.NodeFactory.js
index 5a408ed..39b3473 100644
--- a/src/dm/ve.dm.NodeFactory.js
+++ b/src/dm/ve.dm.NodeFactory.js
@@ -140,6 +140,21 @@
 };
 
 /**
+ * Check if a node is unwrappable.
+ *
+ * @method
+ * @param {string} type Node type
+ * @return {boolean} Whether the node is unwrappable
+ * @throws {Error} Unknown node type
+ */
+ve.dm.NodeFactory.prototype.isNodeUnwrappable = function ( type ) {
+       if ( Object.prototype.hasOwnProperty.call( this.registry, type ) ) {
+               return this.isNodeWrapped( type ) && this.registry[ type 
].static.isUnwrappable;
+       }
+       throw new Error( 'Unknown node type: ' + type );
+};
+
+/**
  * Check if a node can contain content.
  *
  * @method
diff --git a/src/ve.Node.js b/src/ve.Node.js
index dd67278..0cdd9fb 100644
--- a/src/ve.Node.js
+++ b/src/ve.Node.js
@@ -135,6 +135,17 @@
 ve.Node.prototype.isWrapped = null;
 
 /**
+ * Check if the node can be unwrapped.
+ *
+ * Can only be true of the node is wrapped.
+ *
+ * @method
+ * @abstract
+ * @return {boolean} Node represents a unwrappable element
+ */
+ve.Node.prototype.isUnwrappable = null;
+
+/**
  * Check if the node is focusable
  *
  * @method

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I76570eedbbd5a0d0338508432e1a323721d48810
Gerrit-PatchSet: 3
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Esanders <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to