Catrope has uploaded a new change for review.

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


Change subject: Paragraph->heading conversion was broken when cursor next to an 
inline node
......................................................................

Paragraph->heading conversion was broken when cursor next to an inline node

In this case, selectNodes() returns the paragraph, which is not a content
node, and so newFromContentBranchConversion() decides to do nothing at all.

This change makes newFromContentBranchConversion() more intelligent about
finding the content branch to operate on, fixing cases such as these where
selectNodes() returns the content branch itself rather than one of its
children.

Bug: 41023
Change-Id: I710fbf184ef5ef84d9c2f5bca2b115e0660f5b8f
---
M modules/ve/dm/ve.dm.Transaction.js
M modules/ve/test/dm/ve.dm.Transaction.test.js
M modules/ve/test/dm/ve.dm.example.js
3 files changed, 116 insertions(+), 2 deletions(-)


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

diff --git a/modules/ve/dm/ve.dm.Transaction.js 
b/modules/ve/dm/ve.dm.Transaction.js
index d8ce506..6aa3319 100644
--- a/modules/ve/dm/ve.dm.Transaction.js
+++ b/modules/ve/dm/ve.dm.Transaction.js
@@ -396,8 +396,8 @@
        // Replace the wrappings of each content branch in the range
        for ( i = 0; i < selection.length; i++ ) {
                selected = selection[i];
-               if ( selected.node.isContent() ) {
-                       branch = selected.node.getParent();
+               branch = selected.node.isContent() ? selected.node.getParent() 
: selected.node;
+               if ( branch.canContainContent() ) {
                        // Skip branches that are already of the target type 
and have identical attributes
                        if ( branch.getType() === type && ve.compareObjects( 
branch.getAttributes(), attr ) ) {
                                continue;
diff --git a/modules/ve/test/dm/ve.dm.Transaction.test.js 
b/modules/ve/test/dm/ve.dm.Transaction.test.js
index 9189f47..6550974 100644
--- a/modules/ve/test/dm/ve.dm.Transaction.test.js
+++ b/modules/ve/test/dm/ve.dm.Transaction.test.js
@@ -800,6 +800,7 @@
 QUnit.test( 'newFromContentBranchConversion', function ( assert ) {
        var i, key, store,
                doc = ve.dm.example.createExampleDocument(),
+               doc2 = ve.dm.example.createExampleDocument( 'inlineAtEdges' ),
                cases = {
                        'range inside a heading, convert to paragraph': {
                                'args': [doc, new ve.Range( 1, 2 ), 
'paragraph'],
@@ -847,6 +848,102 @@
                                        },
                                        { 'type': 'retain', 'length': 3 }
                                ]
+                       },
+                       'zero-length range before inline node at the start': {
+                               'args': [doc2, new ve.Range( 1, 1 ), 'heading', 
{ 'level': 2 }],
+                               'ops': [
+                                       {
+                                               'type': 'replace',
+                                               'remove': [{ 'type': 
'paragraph' }],
+                                               'insert': [{ 'type': 'heading', 
'attributes': { 'level': 2 } }]
+                                       },
+                                       { 'type': 'retain', 'length': 7 },
+                                       {
+                                               'type': 'replace',
+                                               'remove': [{ 'type': 
'/paragraph' }],
+                                               'insert': [{ 'type': '/heading' 
}]
+                                       }
+                               ]
+                       },
+                       'zero-length range inside inline node at the start': {
+                               'args': [doc2, new ve.Range( 2, 2 ), 'heading', 
{ 'level': 2 }],
+                               'ops': [
+                                       {
+                                               'type': 'replace',
+                                               'remove': [{ 'type': 
'paragraph' }],
+                                               'insert': [{ 'type': 'heading', 
'attributes': { 'level': 2 } }]
+                                       },
+                                       { 'type': 'retain', 'length': 7 },
+                                       {
+                                               'type': 'replace',
+                                               'remove': [{ 'type': 
'/paragraph' }],
+                                               'insert': [{ 'type': '/heading' 
}]
+                                       }
+                               ]
+                       },
+                       'zero-length range after inline node at the start': {
+                               'args': [doc2, new ve.Range( 3, 3 ), 'heading', 
{ 'level': 2 }],
+                               'ops': [
+                                       {
+                                               'type': 'replace',
+                                               'remove': [{ 'type': 
'paragraph' }],
+                                               'insert': [{ 'type': 'heading', 
'attributes': { 'level': 2 } }]
+                                       },
+                                       { 'type': 'retain', 'length': 7 },
+                                       {
+                                               'type': 'replace',
+                                               'remove': [{ 'type': 
'/paragraph' }],
+                                               'insert': [{ 'type': '/heading' 
}]
+                                       }
+                               ]
+                       },
+                       'zero-length range before inline node at the end': {
+                               'args': [doc2, new ve.Range( 6, 6 ), 'heading', 
{ 'level': 2 }],
+                               'ops': [
+                                       {
+                                               'type': 'replace',
+                                               'remove': [{ 'type': 
'paragraph' }],
+                                               'insert': [{ 'type': 'heading', 
'attributes': { 'level': 2 } }]
+                                       },
+                                       { 'type': 'retain', 'length': 7 },
+                                       {
+                                               'type': 'replace',
+                                               'remove': [{ 'type': 
'/paragraph' }],
+                                               'insert': [{ 'type': '/heading' 
}]
+                                       }
+                               ]
+                       },
+                       'zero-length range inside inline node at the end': {
+                               'args': [doc2, new ve.Range( 7, 7 ), 'heading', 
{ 'level': 2 }],
+                               'ops': [
+                                       {
+                                               'type': 'replace',
+                                               'remove': [{ 'type': 
'paragraph' }],
+                                               'insert': [{ 'type': 'heading', 
'attributes': { 'level': 2 } }]
+                                       },
+                                       { 'type': 'retain', 'length': 7 },
+                                       {
+                                               'type': 'replace',
+                                               'remove': [{ 'type': 
'/paragraph' }],
+                                               'insert': [{ 'type': '/heading' 
}]
+                                       }
+                               ]
+                       },
+                       'zero-length range after inline node at the end': {
+                               'args': [doc2, new ve.Range( 8, 8 ), 'heading', 
{ 'level': 2 }],
+                               'ops': [
+                                       {
+                                               'type': 'replace',
+                                               'remove': [{ 'type': 
'paragraph' }],
+                                               'insert': [{ 'type': 'heading', 
'attributes': { 'level': 2 } }]
+                                       },
+                                       { 'type': 'retain', 'length': 7 },
+                                       {
+                                               'type': 'replace',
+                                               'remove': [{ 'type': 
'/paragraph' }],
+                                               'insert': [{ 'type': '/heading' 
}]
+                                       },
+                               ]
                        }
                };
        QUnit.expect( ve.getObjectKeys( cases ).length );
diff --git a/modules/ve/test/dm/ve.dm.example.js 
b/modules/ve/test/dm/ve.dm.example.js
index 01086f5..6c8de4a 100644
--- a/modules/ve/test/dm/ve.dm.example.js
+++ b/modules/ve/test/dm/ve.dm.example.js
@@ -627,6 +627,23 @@
        { 'type': '/table' }
 ];
 
+ve.dm.example.inlineAtEdges = [
+       { 'type': 'paragraph' },
+       { 'type': 'image', 'attributes': {
+               'html/0/src': ve.dm.example.imgSrc,
+               'src': ve.dm.example.imgSrc,
+               'width': null,
+               'height': null
+       } },
+       { 'type': '/image' },
+       'F',
+       'o',
+       'o',
+       { 'type': 'alienInline', 'attributes': { 'html': '<foobar />' } },
+       { 'type': '/alienInline' },
+       { 'type': '/paragraph' }
+];
+
 /**
  * Sample content data index.
  *

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I710fbf184ef5ef84d9c2f5bca2b115e0660f5b8f
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