Skip to content

Commit 3a64969

Browse files
committed
Setup slugs in TreeModifier
Bug: T175852 Bug: T175943 Change-Id: I9cea81cfe71d97a38e3fdf30015d8389eedde756
1 parent 307746d commit 3a64969

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

src/ce/ve.ce.BranchNode.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,9 @@ ve.ce.BranchNode.prototype.onSplice = function ( index ) {
243243
}
244244
}
245245

246+
// TODO: restructure to clarify the logic (exactly one of these is a no-op)
246247
this.setupBlockSlugs();
248+
this.setupInlineSlugs();
247249
};
248250

249251
/**

src/dm/ve.dm.BranchNode.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ ve.dm.BranchNode.prototype.splice = function () {
155155

156156
/**
157157
* Setup a sparse array of booleans indicating where to place slugs
158+
*
159+
* TODO: The function name is misleading: in ContentBranchNodes it sets up inline slugs
158160
*/
159161
ve.dm.BranchNode.prototype.setupBlockSlugs = function () {
160162
var i, len,

src/dm/ve.dm.TreeModifier.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,9 @@ ve.dm.TreeModifier.prototype.insertText = function ( data ) {
649649
*/
650650
ve.dm.TreeModifier.prototype.create = function ( data ) {
651651
var node = ve.dm.nodeFactory.createFromElement( data[ 0 ] );
652+
if ( node instanceof ve.dm.BranchNode ) {
653+
node.setupBlockSlugs();
654+
}
652655
this.ensureNotTextNode();
653656
this.insertNode( node, data );
654657
};

tests/dm/ve.dm.TreeModifier.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,25 @@ QUnit.test( 'modify', function ( assert ) {
114114
'Modified tree matches rebuilt tree, reversed'
115115
);
116116
} );
117+
118+
QUnit.test( 'setupBlockSlugs', function ( assert ) {
119+
var doc = new ve.dm.Surface(
120+
ve.dm.example.createExampleDocumentFromData( [] )
121+
).documentModel;
122+
123+
assert.expect( 1 );
124+
125+
doc.commit( new ve.dm.Transaction( [ {
126+
type: 'replace',
127+
remove: [],
128+
insert: [ { type: 'paragraph' }, { type: '/paragraph' } ],
129+
insertedDataOffset: 0,
130+
insertedDataLength: 2
131+
} ] ) );
132+
133+
assert.deepEqual(
134+
doc.getDocumentNode().getChildren()[ 0 ].slugPositions,
135+
{ 0: true },
136+
'Modified paragraph node contains a slug'
137+
);
138+
} );

0 commit comments

Comments
 (0)