|
@@ -71,7 +71,7 @@ describe( 'TreeWalker', () => {
|
|
|
|
|
|
|
|
it( 'should throw if walking direction is unknown', () => {
|
|
it( 'should throw if walking direction is unknown', () => {
|
|
|
expect( () => {
|
|
expect( () => {
|
|
|
- new TreeWalker( { startPosition: rootBeginning, direction: 'UNKNOWN' } );
|
|
|
|
|
|
|
+ new TreeWalker( { startPosition: rootBeginning, direction: 'unknown' } );
|
|
|
} ).to.throw( CKEditorError, /^tree-walker-unknown-direction/ );
|
|
} ).to.throw( CKEditorError, /^tree-walker-unknown-direction/ );
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
@@ -82,67 +82,67 @@ describe( 'TreeWalker', () => {
|
|
|
beforeEach( () => {
|
|
beforeEach( () => {
|
|
|
expected = [
|
|
expected = [
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_START',
|
|
|
|
|
|
|
+ type: 'elementStart',
|
|
|
item: img1,
|
|
item: img1,
|
|
|
previousPosition: new Position( root, 0 ),
|
|
previousPosition: new Position( root, 0 ),
|
|
|
nextPosition: new Position( img1, 0 )
|
|
nextPosition: new Position( img1, 0 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_END',
|
|
|
|
|
|
|
+ type: 'elementEnd',
|
|
|
item: img1,
|
|
item: img1,
|
|
|
previousPosition: new Position( img1, 0 ),
|
|
previousPosition: new Position( img1, 0 ),
|
|
|
nextPosition: new Position( root, 1 )
|
|
nextPosition: new Position( root, 1 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_START',
|
|
|
|
|
|
|
+ type: 'elementStart',
|
|
|
item: paragraph,
|
|
item: paragraph,
|
|
|
previousPosition: new Position( root, 1 ),
|
|
previousPosition: new Position( root, 1 ),
|
|
|
nextPosition: new Position( paragraph, 0 )
|
|
nextPosition: new Position( paragraph, 0 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_START',
|
|
|
|
|
|
|
+ type: 'elementStart',
|
|
|
item: bold,
|
|
item: bold,
|
|
|
previousPosition: new Position( paragraph, 0 ),
|
|
previousPosition: new Position( paragraph, 0 ),
|
|
|
nextPosition: new Position( bold, 0 )
|
|
nextPosition: new Position( bold, 0 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'TEXT',
|
|
|
|
|
|
|
+ type: 'text',
|
|
|
text: 'abcd',
|
|
text: 'abcd',
|
|
|
previousPosition: new Position( bold, 0 ),
|
|
previousPosition: new Position( bold, 0 ),
|
|
|
nextPosition: new Position( bold, 1 )
|
|
nextPosition: new Position( bold, 1 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_END',
|
|
|
|
|
|
|
+ type: 'elementEnd',
|
|
|
item: bold,
|
|
item: bold,
|
|
|
previousPosition: new Position( bold, 1 ),
|
|
previousPosition: new Position( bold, 1 ),
|
|
|
nextPosition: new Position( paragraph, 1 )
|
|
nextPosition: new Position( paragraph, 1 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'TEXT',
|
|
|
|
|
|
|
+ type: 'text',
|
|
|
text: 'y',
|
|
text: 'y',
|
|
|
previousPosition: new Position( paragraph, 1 ),
|
|
previousPosition: new Position( paragraph, 1 ),
|
|
|
nextPosition: new Position( paragraph, 2 )
|
|
nextPosition: new Position( paragraph, 2 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_START',
|
|
|
|
|
|
|
+ type: 'elementStart',
|
|
|
item: img2,
|
|
item: img2,
|
|
|
previousPosition: new Position( paragraph, 2 ),
|
|
previousPosition: new Position( paragraph, 2 ),
|
|
|
nextPosition: new Position( img2, 0 )
|
|
nextPosition: new Position( img2, 0 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_END',
|
|
|
|
|
|
|
+ type: 'elementEnd',
|
|
|
item: img2,
|
|
item: img2,
|
|
|
previousPosition: new Position( img2, 0 ),
|
|
previousPosition: new Position( img2, 0 ),
|
|
|
nextPosition: new Position( paragraph, 3 )
|
|
nextPosition: new Position( paragraph, 3 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'TEXT',
|
|
|
|
|
|
|
+ type: 'text',
|
|
|
text: 'x',
|
|
text: 'x',
|
|
|
previousPosition: new Position( paragraph, 3 ),
|
|
previousPosition: new Position( paragraph, 3 ),
|
|
|
nextPosition: new Position( paragraph, 4 )
|
|
nextPosition: new Position( paragraph, 4 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_END',
|
|
|
|
|
|
|
+ type: 'elementEnd',
|
|
|
item: paragraph,
|
|
item: paragraph,
|
|
|
previousPosition: new Position( paragraph, 4 ),
|
|
previousPosition: new Position( paragraph, 4 ),
|
|
|
nextPosition: new Position( root, 2 )
|
|
nextPosition: new Position( root, 2 )
|
|
@@ -150,7 +150,7 @@ describe( 'TreeWalker', () => {
|
|
|
];
|
|
];
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- it( 'should provide iterator interface with default FORWARD direction', () => {
|
|
|
|
|
|
|
+ it( 'should provide iterator interface with default forward direction', () => {
|
|
|
let iterator = new TreeWalker( { startPosition: rootBeginning } );
|
|
let iterator = new TreeWalker( { startPosition: rootBeginning } );
|
|
|
let i = 0;
|
|
let i = 0;
|
|
|
|
|
|
|
@@ -161,8 +161,8 @@ describe( 'TreeWalker', () => {
|
|
|
expect( i ).to.equal( expected.length );
|
|
expect( i ).to.equal( expected.length );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- it( 'should provide iterator interface with FORWARD direction', () => {
|
|
|
|
|
- let iterator = new TreeWalker( { startPosition: rootBeginning, direction: 'FORWARD' } );
|
|
|
|
|
|
|
+ it( 'should provide iterator interface with forward direction', () => {
|
|
|
|
|
+ let iterator = new TreeWalker( { startPosition: rootBeginning, direction: 'forward' } );
|
|
|
let i = 0;
|
|
let i = 0;
|
|
|
|
|
|
|
|
for ( let value of iterator ) {
|
|
for ( let value of iterator ) {
|
|
@@ -172,12 +172,12 @@ describe( 'TreeWalker', () => {
|
|
|
expect( i ).to.equal( expected.length );
|
|
expect( i ).to.equal( expected.length );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- it( 'should provide iterator interface which BACKWARD direction', () => {
|
|
|
|
|
- let iterator = new TreeWalker( { startPosition: rootEnding, direction: 'BACKWARD' } );
|
|
|
|
|
|
|
+ it( 'should provide iterator interface which backward direction', () => {
|
|
|
|
|
+ let iterator = new TreeWalker( { startPosition: rootEnding, direction: 'backward' } );
|
|
|
let i = expected.length;
|
|
let i = expected.length;
|
|
|
|
|
|
|
|
for ( let value of iterator ) {
|
|
for ( let value of iterator ) {
|
|
|
- expectValue( value, expected[ --i ], { direction: 'BACKWARD' } );
|
|
|
|
|
|
|
+ expectValue( value, expected[ --i ], { direction: 'backward' } );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
expect( i ).to.equal( 0 );
|
|
expect( i ).to.equal( 0 );
|
|
@@ -197,24 +197,24 @@ describe( 'TreeWalker', () => {
|
|
|
it( 'should start iterating at the startPosition witch is not a root bound, going backward', () => {
|
|
it( 'should start iterating at the startPosition witch is not a root bound, going backward', () => {
|
|
|
let expected = [
|
|
let expected = [
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_START',
|
|
|
|
|
|
|
+ type: 'elementStart',
|
|
|
item: img1,
|
|
item: img1,
|
|
|
previousPosition: new Position( root, 0 ),
|
|
previousPosition: new Position( root, 0 ),
|
|
|
nextPosition: new Position( img1, 0 )
|
|
nextPosition: new Position( img1, 0 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_END',
|
|
|
|
|
|
|
+ type: 'elementEnd',
|
|
|
item: img1,
|
|
item: img1,
|
|
|
previousPosition: new Position( img1, 0 ),
|
|
previousPosition: new Position( img1, 0 ),
|
|
|
nextPosition: new Position( root, 1 )
|
|
nextPosition: new Position( root, 1 )
|
|
|
}
|
|
}
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
- let iterator = new TreeWalker( { startPosition: new Position( root, 1 ), direction: 'BACKWARD' } );
|
|
|
|
|
|
|
+ let iterator = new TreeWalker( { startPosition: new Position( root, 1 ), direction: 'backward' } );
|
|
|
let i = expected.length;
|
|
let i = expected.length;
|
|
|
|
|
|
|
|
for ( let value of iterator ) {
|
|
for ( let value of iterator ) {
|
|
|
- expectValue( value, expected[ --i ], { direction: 'BACKWARD' } );
|
|
|
|
|
|
|
+ expectValue( value, expected[ --i ], { direction: 'backward' } );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
expect( i ).to.equal( 0 );
|
|
expect( i ).to.equal( 0 );
|
|
@@ -228,43 +228,43 @@ describe( 'TreeWalker', () => {
|
|
|
before( () => {
|
|
before( () => {
|
|
|
expected = [
|
|
expected = [
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_START',
|
|
|
|
|
|
|
+ type: 'elementStart',
|
|
|
item: paragraph,
|
|
item: paragraph,
|
|
|
previousPosition: new Position( root, 1 ),
|
|
previousPosition: new Position( root, 1 ),
|
|
|
nextPosition: new Position( paragraph, 0 )
|
|
nextPosition: new Position( paragraph, 0 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_START',
|
|
|
|
|
|
|
+ type: 'elementStart',
|
|
|
item: bold,
|
|
item: bold,
|
|
|
previousPosition: new Position( paragraph, 0 ),
|
|
previousPosition: new Position( paragraph, 0 ),
|
|
|
nextPosition: new Position( bold, 0 )
|
|
nextPosition: new Position( bold, 0 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'TEXT',
|
|
|
|
|
|
|
+ type: 'text',
|
|
|
text: 'abcd',
|
|
text: 'abcd',
|
|
|
previousPosition: new Position( bold, 0 ),
|
|
previousPosition: new Position( bold, 0 ),
|
|
|
nextPosition: new Position( bold, 1 )
|
|
nextPosition: new Position( bold, 1 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_END',
|
|
|
|
|
|
|
+ type: 'elementEnd',
|
|
|
item: bold,
|
|
item: bold,
|
|
|
previousPosition: new Position( bold, 1 ),
|
|
previousPosition: new Position( bold, 1 ),
|
|
|
nextPosition: new Position( paragraph, 1 )
|
|
nextPosition: new Position( paragraph, 1 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'TEXT',
|
|
|
|
|
|
|
+ type: 'text',
|
|
|
text: 'y',
|
|
text: 'y',
|
|
|
previousPosition: new Position( paragraph, 1 ),
|
|
previousPosition: new Position( paragraph, 1 ),
|
|
|
nextPosition: new Position( paragraph, 2 )
|
|
nextPosition: new Position( paragraph, 2 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_START',
|
|
|
|
|
|
|
+ type: 'elementStart',
|
|
|
item: img2,
|
|
item: img2,
|
|
|
previousPosition: new Position( paragraph, 2 ),
|
|
previousPosition: new Position( paragraph, 2 ),
|
|
|
nextPosition: new Position( img2, 0 )
|
|
nextPosition: new Position( img2, 0 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_END',
|
|
|
|
|
|
|
+ type: 'elementEnd',
|
|
|
item: img2,
|
|
item: img2,
|
|
|
previousPosition: new Position( img2, 0 ),
|
|
previousPosition: new Position( img2, 0 ),
|
|
|
nextPosition: new Position( paragraph, 3 )
|
|
nextPosition: new Position( paragraph, 3 )
|
|
@@ -286,11 +286,11 @@ describe( 'TreeWalker', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should iterating over the range going backward', () => {
|
|
it( 'should iterating over the range going backward', () => {
|
|
|
- let iterator = new TreeWalker( { boundaries: range, direction: 'BACKWARD' } );
|
|
|
|
|
|
|
+ let iterator = new TreeWalker( { boundaries: range, direction: 'backward' } );
|
|
|
let i = expected.length;
|
|
let i = expected.length;
|
|
|
|
|
|
|
|
for ( let value of iterator ) {
|
|
for ( let value of iterator ) {
|
|
|
- expectValue( value, expected[ --i ], { direction: 'BACKWARD' } );
|
|
|
|
|
|
|
+ expectValue( value, expected[ --i ], { direction: 'backward' } );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
expect( i ).to.equal( 0 );
|
|
expect( i ).to.equal( 0 );
|
|
@@ -303,31 +303,31 @@ describe( 'TreeWalker', () => {
|
|
|
before( () => {
|
|
before( () => {
|
|
|
expected = [
|
|
expected = [
|
|
|
{
|
|
{
|
|
|
- type: 'TEXT',
|
|
|
|
|
|
|
+ type: 'text',
|
|
|
text: 'bcd',
|
|
text: 'bcd',
|
|
|
previousPosition: new Position( textAbcd, 1 ),
|
|
previousPosition: new Position( textAbcd, 1 ),
|
|
|
nextPosition: new Position( bold, 1 )
|
|
nextPosition: new Position( bold, 1 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_END',
|
|
|
|
|
|
|
+ type: 'elementEnd',
|
|
|
item: bold,
|
|
item: bold,
|
|
|
previousPosition: new Position( bold, 1 ),
|
|
previousPosition: new Position( bold, 1 ),
|
|
|
nextPosition: new Position( paragraph, 1 )
|
|
nextPosition: new Position( paragraph, 1 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'TEXT',
|
|
|
|
|
|
|
+ type: 'text',
|
|
|
text: 'y',
|
|
text: 'y',
|
|
|
previousPosition: new Position( paragraph, 1 ),
|
|
previousPosition: new Position( paragraph, 1 ),
|
|
|
nextPosition: new Position( paragraph, 2 )
|
|
nextPosition: new Position( paragraph, 2 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_START',
|
|
|
|
|
|
|
+ type: 'elementStart',
|
|
|
item: img2,
|
|
item: img2,
|
|
|
previousPosition: new Position( paragraph, 2 ),
|
|
previousPosition: new Position( paragraph, 2 ),
|
|
|
nextPosition: new Position( img2, 0 )
|
|
nextPosition: new Position( img2, 0 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_END',
|
|
|
|
|
|
|
+ type: 'elementEnd',
|
|
|
item: img2,
|
|
item: img2,
|
|
|
previousPosition: new Position( img2, 0 ),
|
|
previousPosition: new Position( img2, 0 ),
|
|
|
nextPosition: new Position( paragraph, 3 )
|
|
nextPosition: new Position( paragraph, 3 )
|
|
@@ -351,13 +351,13 @@ describe( 'TreeWalker', () => {
|
|
|
it( 'should return part of the text going backward', () => {
|
|
it( 'should return part of the text going backward', () => {
|
|
|
let iterator = new TreeWalker( {
|
|
let iterator = new TreeWalker( {
|
|
|
boundaries: range,
|
|
boundaries: range,
|
|
|
- direction: 'BACKWARD'
|
|
|
|
|
|
|
+ direction: 'backward'
|
|
|
}
|
|
}
|
|
|
);
|
|
);
|
|
|
let i = expected.length;
|
|
let i = expected.length;
|
|
|
|
|
|
|
|
for ( let value of iterator ) {
|
|
for ( let value of iterator ) {
|
|
|
- expectValue( value, expected[ --i ], { direction: 'BACKWARD' } );
|
|
|
|
|
|
|
+ expectValue( value, expected[ --i ], { direction: 'backward' } );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
expect( i ).to.equal( 0 );
|
|
expect( i ).to.equal( 0 );
|
|
@@ -370,31 +370,31 @@ describe( 'TreeWalker', () => {
|
|
|
before( () => {
|
|
before( () => {
|
|
|
expected = [
|
|
expected = [
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_START',
|
|
|
|
|
|
|
+ type: 'elementStart',
|
|
|
item: img1,
|
|
item: img1,
|
|
|
previousPosition: new Position( root, 0 ),
|
|
previousPosition: new Position( root, 0 ),
|
|
|
nextPosition: new Position( img1, 0 )
|
|
nextPosition: new Position( img1, 0 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_END',
|
|
|
|
|
|
|
+ type: 'elementEnd',
|
|
|
item: img1,
|
|
item: img1,
|
|
|
previousPosition: new Position( img1, 0 ),
|
|
previousPosition: new Position( img1, 0 ),
|
|
|
nextPosition: new Position( root, 1 )
|
|
nextPosition: new Position( root, 1 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_START',
|
|
|
|
|
|
|
+ type: 'elementStart',
|
|
|
item: paragraph,
|
|
item: paragraph,
|
|
|
previousPosition: new Position( root, 1 ),
|
|
previousPosition: new Position( root, 1 ),
|
|
|
nextPosition: new Position( paragraph, 0 )
|
|
nextPosition: new Position( paragraph, 0 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_START',
|
|
|
|
|
|
|
+ type: 'elementStart',
|
|
|
item: bold,
|
|
item: bold,
|
|
|
previousPosition: new Position( paragraph, 0 ),
|
|
previousPosition: new Position( paragraph, 0 ),
|
|
|
nextPosition: new Position( bold, 0 )
|
|
nextPosition: new Position( bold, 0 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'TEXT',
|
|
|
|
|
|
|
+ type: 'text',
|
|
|
text: 'ab',
|
|
text: 'ab',
|
|
|
previousPosition: new Position( bold, 0 ),
|
|
previousPosition: new Position( bold, 0 ),
|
|
|
nextPosition: new Position( textAbcd, 2 )
|
|
nextPosition: new Position( textAbcd, 2 )
|
|
@@ -419,13 +419,13 @@ describe( 'TreeWalker', () => {
|
|
|
let iterator = new TreeWalker( {
|
|
let iterator = new TreeWalker( {
|
|
|
boundaries: range,
|
|
boundaries: range,
|
|
|
startPosition: range.end,
|
|
startPosition: range.end,
|
|
|
- direction: 'BACKWARD'
|
|
|
|
|
|
|
+ direction: 'backward'
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
let i = expected.length;
|
|
let i = expected.length;
|
|
|
|
|
|
|
|
for ( let value of iterator ) {
|
|
for ( let value of iterator ) {
|
|
|
- expectValue( value, expected[ --i ], { direction: 'BACKWARD' } );
|
|
|
|
|
|
|
+ expectValue( value, expected[ --i ], { direction: 'backward' } );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
expect( i ).to.equal( 0 );
|
|
expect( i ).to.equal( 0 );
|
|
@@ -438,7 +438,7 @@ describe( 'TreeWalker', () => {
|
|
|
before( () => {
|
|
before( () => {
|
|
|
expected = [
|
|
expected = [
|
|
|
{
|
|
{
|
|
|
- type: 'TEXT',
|
|
|
|
|
|
|
+ type: 'text',
|
|
|
text: 'bc',
|
|
text: 'bc',
|
|
|
previousPosition: new Position( textAbcd, 1 ),
|
|
previousPosition: new Position( textAbcd, 1 ),
|
|
|
nextPosition: new Position( textAbcd, 3 )
|
|
nextPosition: new Position( textAbcd, 3 )
|
|
@@ -463,13 +463,13 @@ describe( 'TreeWalker', () => {
|
|
|
let iterator = new TreeWalker( {
|
|
let iterator = new TreeWalker( {
|
|
|
boundaries: range,
|
|
boundaries: range,
|
|
|
startPosition: range.end,
|
|
startPosition: range.end,
|
|
|
- direction: 'BACKWARD'
|
|
|
|
|
|
|
+ direction: 'backward'
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
let i = expected.length;
|
|
let i = expected.length;
|
|
|
|
|
|
|
|
for ( let value of iterator ) {
|
|
for ( let value of iterator ) {
|
|
|
- expectValue( value, expected[ --i ], { direction: 'BACKWARD' } );
|
|
|
|
|
|
|
+ expectValue( value, expected[ --i ], { direction: 'backward' } );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
expect( i ).to.equal( 0 );
|
|
expect( i ).to.equal( 0 );
|
|
@@ -480,19 +480,19 @@ describe( 'TreeWalker', () => {
|
|
|
it( 'should iterating from the start position', () => {
|
|
it( 'should iterating from the start position', () => {
|
|
|
let expected = [
|
|
let expected = [
|
|
|
{
|
|
{
|
|
|
- type: 'TEXT',
|
|
|
|
|
|
|
+ type: 'text',
|
|
|
text: 'y',
|
|
text: 'y',
|
|
|
previousPosition: new Position( paragraph, 1 ),
|
|
previousPosition: new Position( paragraph, 1 ),
|
|
|
nextPosition: new Position( paragraph, 2 )
|
|
nextPosition: new Position( paragraph, 2 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_START',
|
|
|
|
|
|
|
+ type: 'elementStart',
|
|
|
item: img2,
|
|
item: img2,
|
|
|
previousPosition: new Position( paragraph, 2 ),
|
|
previousPosition: new Position( paragraph, 2 ),
|
|
|
nextPosition: new Position( img2, 0 )
|
|
nextPosition: new Position( img2, 0 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_END',
|
|
|
|
|
|
|
+ type: 'elementEnd',
|
|
|
item: img2,
|
|
item: img2,
|
|
|
previousPosition: new Position( img2, 0 ),
|
|
previousPosition: new Position( img2, 0 ),
|
|
|
nextPosition: new Position( paragraph, 3 )
|
|
nextPosition: new Position( paragraph, 3 )
|
|
@@ -517,19 +517,19 @@ describe( 'TreeWalker', () => {
|
|
|
it( 'should iterating from the start position going backward', () => {
|
|
it( 'should iterating from the start position going backward', () => {
|
|
|
let expected = [
|
|
let expected = [
|
|
|
{
|
|
{
|
|
|
- type: 'TEXT',
|
|
|
|
|
|
|
+ type: 'text',
|
|
|
text: 'bcd',
|
|
text: 'bcd',
|
|
|
previousPosition: new Position( textAbcd, 1 ),
|
|
previousPosition: new Position( textAbcd, 1 ),
|
|
|
nextPosition: new Position( bold, 1 )
|
|
nextPosition: new Position( bold, 1 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_END',
|
|
|
|
|
|
|
+ type: 'elementEnd',
|
|
|
item: bold,
|
|
item: bold,
|
|
|
previousPosition: new Position( bold, 1 ),
|
|
previousPosition: new Position( bold, 1 ),
|
|
|
nextPosition: new Position( paragraph, 1 )
|
|
nextPosition: new Position( paragraph, 1 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'TEXT',
|
|
|
|
|
|
|
+ type: 'text',
|
|
|
text: 'y',
|
|
text: 'y',
|
|
|
previousPosition: new Position( paragraph, 1 ),
|
|
previousPosition: new Position( paragraph, 1 ),
|
|
|
nextPosition: new Position( paragraph, 2 )
|
|
nextPosition: new Position( paragraph, 2 )
|
|
@@ -541,12 +541,12 @@ describe( 'TreeWalker', () => {
|
|
|
let iterator = new TreeWalker( {
|
|
let iterator = new TreeWalker( {
|
|
|
boundaries: range,
|
|
boundaries: range,
|
|
|
startPosition: new Position( paragraph, 2 ),
|
|
startPosition: new Position( paragraph, 2 ),
|
|
|
- direction: 'BACKWARD'
|
|
|
|
|
|
|
+ direction: 'backward'
|
|
|
} );
|
|
} );
|
|
|
let i = expected.length;
|
|
let i = expected.length;
|
|
|
|
|
|
|
|
for ( let value of iterator ) {
|
|
for ( let value of iterator ) {
|
|
|
- expectValue( value, expected[ --i ], { direction: 'BACKWARD' } );
|
|
|
|
|
|
|
+ expectValue( value, expected[ --i ], { direction: 'backward' } );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
expect( i ).to.equal( 0 );
|
|
expect( i ).to.equal( 0 );
|
|
@@ -561,85 +561,85 @@ describe( 'TreeWalker', () => {
|
|
|
before( () => {
|
|
before( () => {
|
|
|
expected = [
|
|
expected = [
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_START',
|
|
|
|
|
|
|
+ type: 'elementStart',
|
|
|
item: img1,
|
|
item: img1,
|
|
|
previousPosition: new Position( root, 0 ),
|
|
previousPosition: new Position( root, 0 ),
|
|
|
nextPosition: new Position( img1, 0 )
|
|
nextPosition: new Position( img1, 0 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_END',
|
|
|
|
|
|
|
+ type: 'elementEnd',
|
|
|
item: img1,
|
|
item: img1,
|
|
|
previousPosition: new Position( img1, 0 ),
|
|
previousPosition: new Position( img1, 0 ),
|
|
|
nextPosition: new Position( root, 1 )
|
|
nextPosition: new Position( root, 1 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_START',
|
|
|
|
|
|
|
+ type: 'elementStart',
|
|
|
item: paragraph,
|
|
item: paragraph,
|
|
|
previousPosition: new Position( root, 1 ),
|
|
previousPosition: new Position( root, 1 ),
|
|
|
nextPosition: new Position( paragraph, 0 )
|
|
nextPosition: new Position( paragraph, 0 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_START',
|
|
|
|
|
|
|
+ type: 'elementStart',
|
|
|
item: bold,
|
|
item: bold,
|
|
|
previousPosition: new Position( paragraph, 0 ),
|
|
previousPosition: new Position( paragraph, 0 ),
|
|
|
nextPosition: new Position( bold, 0 )
|
|
nextPosition: new Position( bold, 0 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'TEXT',
|
|
|
|
|
|
|
+ type: 'text',
|
|
|
text: 'a',
|
|
text: 'a',
|
|
|
previousPosition: new Position( bold, 0 ),
|
|
previousPosition: new Position( bold, 0 ),
|
|
|
nextPosition: new Position( textAbcd, 1 )
|
|
nextPosition: new Position( textAbcd, 1 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'TEXT',
|
|
|
|
|
|
|
+ type: 'text',
|
|
|
text: 'b',
|
|
text: 'b',
|
|
|
previousPosition: new Position( textAbcd, 1 ),
|
|
previousPosition: new Position( textAbcd, 1 ),
|
|
|
nextPosition: new Position( textAbcd, 2 )
|
|
nextPosition: new Position( textAbcd, 2 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'TEXT',
|
|
|
|
|
|
|
+ type: 'text',
|
|
|
text: 'c',
|
|
text: 'c',
|
|
|
previousPosition: new Position( textAbcd, 2 ),
|
|
previousPosition: new Position( textAbcd, 2 ),
|
|
|
nextPosition: new Position( textAbcd, 3 )
|
|
nextPosition: new Position( textAbcd, 3 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'TEXT',
|
|
|
|
|
|
|
+ type: 'text',
|
|
|
text: 'd',
|
|
text: 'd',
|
|
|
previousPosition: new Position( textAbcd, 3 ),
|
|
previousPosition: new Position( textAbcd, 3 ),
|
|
|
nextPosition: new Position( bold, 1 )
|
|
nextPosition: new Position( bold, 1 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_END',
|
|
|
|
|
|
|
+ type: 'elementEnd',
|
|
|
item: bold,
|
|
item: bold,
|
|
|
previousPosition: new Position( bold, 1 ),
|
|
previousPosition: new Position( bold, 1 ),
|
|
|
nextPosition: new Position( paragraph, 1 )
|
|
nextPosition: new Position( paragraph, 1 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'TEXT',
|
|
|
|
|
|
|
+ type: 'text',
|
|
|
text: 'y',
|
|
text: 'y',
|
|
|
previousPosition: new Position( paragraph, 1 ),
|
|
previousPosition: new Position( paragraph, 1 ),
|
|
|
nextPosition: new Position( paragraph, 2 )
|
|
nextPosition: new Position( paragraph, 2 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_START',
|
|
|
|
|
|
|
+ type: 'elementStart',
|
|
|
item: img2,
|
|
item: img2,
|
|
|
previousPosition: new Position( paragraph, 2 ),
|
|
previousPosition: new Position( paragraph, 2 ),
|
|
|
nextPosition: new Position( img2, 0 )
|
|
nextPosition: new Position( img2, 0 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_END',
|
|
|
|
|
|
|
+ type: 'elementEnd',
|
|
|
item: img2,
|
|
item: img2,
|
|
|
previousPosition: new Position( img2, 0 ),
|
|
previousPosition: new Position( img2, 0 ),
|
|
|
nextPosition: new Position( paragraph, 3 )
|
|
nextPosition: new Position( paragraph, 3 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'TEXT',
|
|
|
|
|
|
|
+ type: 'text',
|
|
|
text: 'x',
|
|
text: 'x',
|
|
|
previousPosition: new Position( paragraph, 3 ),
|
|
previousPosition: new Position( paragraph, 3 ),
|
|
|
nextPosition: new Position( paragraph, 4 )
|
|
nextPosition: new Position( paragraph, 4 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_END',
|
|
|
|
|
|
|
+ type: 'elementEnd',
|
|
|
item: paragraph,
|
|
item: paragraph,
|
|
|
previousPosition: new Position( paragraph, 4 ),
|
|
previousPosition: new Position( paragraph, 4 ),
|
|
|
nextPosition: new Position( root, 2 )
|
|
nextPosition: new Position( root, 2 )
|
|
@@ -662,12 +662,12 @@ describe( 'TreeWalker', () => {
|
|
|
let iterator = new TreeWalker( {
|
|
let iterator = new TreeWalker( {
|
|
|
startPosition: rootEnding,
|
|
startPosition: rootEnding,
|
|
|
singleCharacters: true,
|
|
singleCharacters: true,
|
|
|
- direction: 'BACKWARD'
|
|
|
|
|
|
|
+ direction: 'backward'
|
|
|
} );
|
|
} );
|
|
|
let i = expected.length;
|
|
let i = expected.length;
|
|
|
|
|
|
|
|
for ( let value of iterator ) {
|
|
for ( let value of iterator ) {
|
|
|
- expectValue( value, expected[ --i ], { direction: 'BACKWARD' } );
|
|
|
|
|
|
|
+ expectValue( value, expected[ --i ], { direction: 'backward' } );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
expect( i ).to.equal( 0 );
|
|
expect( i ).to.equal( 0 );
|
|
@@ -680,43 +680,43 @@ describe( 'TreeWalker', () => {
|
|
|
before( () => {
|
|
before( () => {
|
|
|
expected = [
|
|
expected = [
|
|
|
{
|
|
{
|
|
|
- type: 'TEXT',
|
|
|
|
|
|
|
+ type: 'text',
|
|
|
text: 'a',
|
|
text: 'a',
|
|
|
previousPosition: new Position( bold, 0 ),
|
|
previousPosition: new Position( bold, 0 ),
|
|
|
nextPosition: new Position( textAbcd, 1 )
|
|
nextPosition: new Position( textAbcd, 1 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'TEXT',
|
|
|
|
|
|
|
+ type: 'text',
|
|
|
text: 'b',
|
|
text: 'b',
|
|
|
previousPosition: new Position( textAbcd, 1 ),
|
|
previousPosition: new Position( textAbcd, 1 ),
|
|
|
nextPosition: new Position( textAbcd, 2 )
|
|
nextPosition: new Position( textAbcd, 2 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'TEXT',
|
|
|
|
|
|
|
+ type: 'text',
|
|
|
text: 'c',
|
|
text: 'c',
|
|
|
previousPosition: new Position( textAbcd, 2 ),
|
|
previousPosition: new Position( textAbcd, 2 ),
|
|
|
nextPosition: new Position( textAbcd, 3 )
|
|
nextPosition: new Position( textAbcd, 3 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'TEXT',
|
|
|
|
|
|
|
+ type: 'text',
|
|
|
text: 'd',
|
|
text: 'd',
|
|
|
previousPosition: new Position( textAbcd, 3 ),
|
|
previousPosition: new Position( textAbcd, 3 ),
|
|
|
nextPosition: new Position( bold, 1 )
|
|
nextPosition: new Position( bold, 1 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_END',
|
|
|
|
|
|
|
+ type: 'elementEnd',
|
|
|
item: bold,
|
|
item: bold,
|
|
|
previousPosition: new Position( bold, 1 ),
|
|
previousPosition: new Position( bold, 1 ),
|
|
|
nextPosition: new Position( paragraph, 1 )
|
|
nextPosition: new Position( paragraph, 1 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'TEXT',
|
|
|
|
|
|
|
+ type: 'text',
|
|
|
text: 'y',
|
|
text: 'y',
|
|
|
previousPosition: new Position( paragraph, 1 ),
|
|
previousPosition: new Position( paragraph, 1 ),
|
|
|
nextPosition: new Position( paragraph, 2 )
|
|
nextPosition: new Position( paragraph, 2 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_START',
|
|
|
|
|
|
|
+ type: 'elementStart',
|
|
|
item: img2,
|
|
item: img2,
|
|
|
previousPosition: new Position( paragraph, 2 ),
|
|
previousPosition: new Position( paragraph, 2 ),
|
|
|
nextPosition: new Position( img2, 0 )
|
|
nextPosition: new Position( img2, 0 )
|
|
@@ -741,12 +741,12 @@ describe( 'TreeWalker', () => {
|
|
|
let iterator = new TreeWalker( {
|
|
let iterator = new TreeWalker( {
|
|
|
boundaries: range,
|
|
boundaries: range,
|
|
|
singleCharacters: true,
|
|
singleCharacters: true,
|
|
|
- direction: 'BACKWARD'
|
|
|
|
|
|
|
+ direction: 'backward'
|
|
|
} );
|
|
} );
|
|
|
let i = expected.length;
|
|
let i = expected.length;
|
|
|
|
|
|
|
|
for ( let value of iterator ) {
|
|
for ( let value of iterator ) {
|
|
|
- expectValue( value, expected[ --i ], { direction: 'BACKWARD' } );
|
|
|
|
|
|
|
+ expectValue( value, expected[ --i ], { direction: 'backward' } );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
expect( i ).to.equal( 0 );
|
|
expect( i ).to.equal( 0 );
|
|
@@ -754,19 +754,19 @@ describe( 'TreeWalker', () => {
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- describe( 'iterate omitting child nodes and ELEMENT_END `shallow`', () => {
|
|
|
|
|
|
|
+ describe( 'iterate omitting child nodes and elementEnd `shallow`', () => {
|
|
|
let expected;
|
|
let expected;
|
|
|
|
|
|
|
|
before( () => {
|
|
before( () => {
|
|
|
expected = [
|
|
expected = [
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_START',
|
|
|
|
|
|
|
+ type: 'elementStart',
|
|
|
item: img1,
|
|
item: img1,
|
|
|
previousPosition: new Position( root, 0 ),
|
|
previousPosition: new Position( root, 0 ),
|
|
|
nextPosition: new Position( root, 1 )
|
|
nextPosition: new Position( root, 1 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_START',
|
|
|
|
|
|
|
+ type: 'elementStart',
|
|
|
item: paragraph,
|
|
item: paragraph,
|
|
|
previousPosition: new Position( root, 1 ),
|
|
previousPosition: new Position( root, 1 ),
|
|
|
nextPosition: new Position( root, 2 )
|
|
nextPosition: new Position( root, 2 )
|
|
@@ -786,61 +786,61 @@ describe( 'TreeWalker', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should not enter elements going backward', () => {
|
|
it( 'should not enter elements going backward', () => {
|
|
|
- let iterator = new TreeWalker( { startPosition: rootEnding, shallow: true, direction: 'BACKWARD' } );
|
|
|
|
|
|
|
+ let iterator = new TreeWalker( { startPosition: rootEnding, shallow: true, direction: 'backward' } );
|
|
|
let i = expected.length;
|
|
let i = expected.length;
|
|
|
|
|
|
|
|
for ( let value of iterator ) {
|
|
for ( let value of iterator ) {
|
|
|
- expectValue( value, expected[ --i ], { direction: 'BACKWARD' } );
|
|
|
|
|
|
|
+ expectValue( value, expected[ --i ], { direction: 'backward' } );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
expect( i ).to.equal( 0 );
|
|
expect( i ).to.equal( 0 );
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- describe( 'iterate omitting ELEMENT_END `ignoreElementEnd`', () => {
|
|
|
|
|
|
|
+ describe( 'iterate omitting elementEnd `ignoreElementEnd`', () => {
|
|
|
describe( 'merged text', () => {
|
|
describe( 'merged text', () => {
|
|
|
let expected;
|
|
let expected;
|
|
|
|
|
|
|
|
before( () => {
|
|
before( () => {
|
|
|
expected = [
|
|
expected = [
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_START',
|
|
|
|
|
|
|
+ type: 'elementStart',
|
|
|
item: img1,
|
|
item: img1,
|
|
|
previousPosition: new Position( root, 0 ),
|
|
previousPosition: new Position( root, 0 ),
|
|
|
nextPosition: new Position( img1, 0 )
|
|
nextPosition: new Position( img1, 0 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_START',
|
|
|
|
|
|
|
+ type: 'elementStart',
|
|
|
item: paragraph,
|
|
item: paragraph,
|
|
|
previousPosition: new Position( root, 1 ),
|
|
previousPosition: new Position( root, 1 ),
|
|
|
nextPosition: new Position( paragraph, 0 )
|
|
nextPosition: new Position( paragraph, 0 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_START',
|
|
|
|
|
|
|
+ type: 'elementStart',
|
|
|
item: bold,
|
|
item: bold,
|
|
|
previousPosition: new Position( paragraph, 0 ),
|
|
previousPosition: new Position( paragraph, 0 ),
|
|
|
nextPosition: new Position( bold, 0 )
|
|
nextPosition: new Position( bold, 0 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'TEXT',
|
|
|
|
|
|
|
+ type: 'text',
|
|
|
text: 'abcd',
|
|
text: 'abcd',
|
|
|
previousPosition: new Position( bold, 0 ),
|
|
previousPosition: new Position( bold, 0 ),
|
|
|
nextPosition: new Position( bold, 1 )
|
|
nextPosition: new Position( bold, 1 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'TEXT',
|
|
|
|
|
|
|
+ type: 'text',
|
|
|
text: 'y',
|
|
text: 'y',
|
|
|
previousPosition: new Position( paragraph, 1 ),
|
|
previousPosition: new Position( paragraph, 1 ),
|
|
|
nextPosition: new Position( paragraph, 2 )
|
|
nextPosition: new Position( paragraph, 2 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_START',
|
|
|
|
|
|
|
+ type: 'elementStart',
|
|
|
item: img2,
|
|
item: img2,
|
|
|
previousPosition: new Position( paragraph, 2 ),
|
|
previousPosition: new Position( paragraph, 2 ),
|
|
|
nextPosition: new Position( img2, 0 )
|
|
nextPosition: new Position( img2, 0 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'TEXT',
|
|
|
|
|
|
|
+ type: 'text',
|
|
|
text: 'x',
|
|
text: 'x',
|
|
|
previousPosition: new Position( paragraph, 3 ),
|
|
previousPosition: new Position( paragraph, 3 ),
|
|
|
nextPosition: new Position( paragraph, 4 )
|
|
nextPosition: new Position( paragraph, 4 )
|
|
@@ -848,7 +848,7 @@ describe( 'TreeWalker', () => {
|
|
|
];
|
|
];
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- it( 'should iterate ignoring ELEMENT_END', () => {
|
|
|
|
|
|
|
+ it( 'should iterate ignoring elementEnd', () => {
|
|
|
let iterator = new TreeWalker( { startPosition: rootBeginning, ignoreElementEnd: true } );
|
|
let iterator = new TreeWalker( { startPosition: rootBeginning, ignoreElementEnd: true } );
|
|
|
let i = 0;
|
|
let i = 0;
|
|
|
|
|
|
|
@@ -859,16 +859,16 @@ describe( 'TreeWalker', () => {
|
|
|
expect( i ).to.equal( expected.length );
|
|
expect( i ).to.equal( expected.length );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- it( 'should iterate ignoring ELEMENT_END going backward', () => {
|
|
|
|
|
|
|
+ it( 'should iterate ignoring elementEnd going backward', () => {
|
|
|
let iterator = new TreeWalker( {
|
|
let iterator = new TreeWalker( {
|
|
|
startPosition: rootEnding,
|
|
startPosition: rootEnding,
|
|
|
ignoreElementEnd: true,
|
|
ignoreElementEnd: true,
|
|
|
- direction: 'BACKWARD'
|
|
|
|
|
|
|
+ direction: 'backward'
|
|
|
} );
|
|
} );
|
|
|
let i = expected.length;
|
|
let i = expected.length;
|
|
|
|
|
|
|
|
for ( let value of iterator ) {
|
|
for ( let value of iterator ) {
|
|
|
- expectValue( value, expected[ --i ], { direction: 'BACKWARD' } );
|
|
|
|
|
|
|
+ expectValue( value, expected[ --i ], { direction: 'backward' } );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
expect( i ).to.equal( 0 );
|
|
expect( i ).to.equal( 0 );
|
|
@@ -881,61 +881,61 @@ describe( 'TreeWalker', () => {
|
|
|
before( () => {
|
|
before( () => {
|
|
|
expected = [
|
|
expected = [
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_START',
|
|
|
|
|
|
|
+ type: 'elementStart',
|
|
|
item: img1,
|
|
item: img1,
|
|
|
previousPosition: new Position( root, 0 ),
|
|
previousPosition: new Position( root, 0 ),
|
|
|
nextPosition: new Position( img1, 0 )
|
|
nextPosition: new Position( img1, 0 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_START',
|
|
|
|
|
|
|
+ type: 'elementStart',
|
|
|
item: paragraph,
|
|
item: paragraph,
|
|
|
previousPosition: new Position( root, 1 ),
|
|
previousPosition: new Position( root, 1 ),
|
|
|
nextPosition: new Position( paragraph, 0 )
|
|
nextPosition: new Position( paragraph, 0 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_START',
|
|
|
|
|
|
|
+ type: 'elementStart',
|
|
|
item: bold,
|
|
item: bold,
|
|
|
previousPosition: new Position( paragraph, 0 ),
|
|
previousPosition: new Position( paragraph, 0 ),
|
|
|
nextPosition: new Position( bold, 0 )
|
|
nextPosition: new Position( bold, 0 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'TEXT',
|
|
|
|
|
|
|
+ type: 'text',
|
|
|
text: 'a',
|
|
text: 'a',
|
|
|
previousPosition: new Position( bold, 0 ),
|
|
previousPosition: new Position( bold, 0 ),
|
|
|
nextPosition: new Position( textAbcd, 1 )
|
|
nextPosition: new Position( textAbcd, 1 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'TEXT',
|
|
|
|
|
|
|
+ type: 'text',
|
|
|
text: 'b',
|
|
text: 'b',
|
|
|
previousPosition: new Position( textAbcd, 1 ),
|
|
previousPosition: new Position( textAbcd, 1 ),
|
|
|
nextPosition: new Position( textAbcd, 2 )
|
|
nextPosition: new Position( textAbcd, 2 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'TEXT',
|
|
|
|
|
|
|
+ type: 'text',
|
|
|
text: 'c',
|
|
text: 'c',
|
|
|
previousPosition: new Position( textAbcd, 2 ),
|
|
previousPosition: new Position( textAbcd, 2 ),
|
|
|
nextPosition: new Position( textAbcd, 3 )
|
|
nextPosition: new Position( textAbcd, 3 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'TEXT',
|
|
|
|
|
|
|
+ type: 'text',
|
|
|
text: 'd',
|
|
text: 'd',
|
|
|
previousPosition: new Position( textAbcd, 3 ),
|
|
previousPosition: new Position( textAbcd, 3 ),
|
|
|
nextPosition: new Position( bold, 1 )
|
|
nextPosition: new Position( bold, 1 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'TEXT',
|
|
|
|
|
|
|
+ type: 'text',
|
|
|
text: 'y',
|
|
text: 'y',
|
|
|
previousPosition: new Position( paragraph, 1 ),
|
|
previousPosition: new Position( paragraph, 1 ),
|
|
|
nextPosition: new Position( paragraph, 2 )
|
|
nextPosition: new Position( paragraph, 2 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'ELEMENT_START',
|
|
|
|
|
|
|
+ type: 'elementStart',
|
|
|
item: img2,
|
|
item: img2,
|
|
|
previousPosition: new Position( paragraph, 2 ),
|
|
previousPosition: new Position( paragraph, 2 ),
|
|
|
nextPosition: new Position( img2, 0 )
|
|
nextPosition: new Position( img2, 0 )
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- type: 'TEXT',
|
|
|
|
|
|
|
+ type: 'text',
|
|
|
text: 'x',
|
|
text: 'x',
|
|
|
previousPosition: new Position( paragraph, 3 ),
|
|
previousPosition: new Position( paragraph, 3 ),
|
|
|
nextPosition: new Position( paragraph, 4 )
|
|
nextPosition: new Position( paragraph, 4 )
|
|
@@ -943,7 +943,7 @@ describe( 'TreeWalker', () => {
|
|
|
];
|
|
];
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- it( 'should return single characters ignoring ELEMENT_END', () => {
|
|
|
|
|
|
|
+ it( 'should return single characters ignoring elementEnd', () => {
|
|
|
let iterator = new TreeWalker( {
|
|
let iterator = new TreeWalker( {
|
|
|
startPosition: rootBeginning,
|
|
startPosition: rootBeginning,
|
|
|
singleCharacters: true,
|
|
singleCharacters: true,
|
|
@@ -958,17 +958,17 @@ describe( 'TreeWalker', () => {
|
|
|
expect( i ).to.equal( expected.length );
|
|
expect( i ).to.equal( expected.length );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- it( 'should return single characters ignoring ELEMENT_END going backward', () => {
|
|
|
|
|
|
|
+ it( 'should return single characters ignoring elementEnd going backward', () => {
|
|
|
let iterator = new TreeWalker( {
|
|
let iterator = new TreeWalker( {
|
|
|
startPosition: rootEnding,
|
|
startPosition: rootEnding,
|
|
|
singleCharacters: true,
|
|
singleCharacters: true,
|
|
|
ignoreElementEnd: true,
|
|
ignoreElementEnd: true,
|
|
|
- direction: 'BACKWARD'
|
|
|
|
|
|
|
+ direction: 'backward'
|
|
|
} );
|
|
} );
|
|
|
let i = expected.length;
|
|
let i = expected.length;
|
|
|
|
|
|
|
|
for ( let value of iterator ) {
|
|
for ( let value of iterator ) {
|
|
|
- expectValue( value, expected[ --i ], { direction: 'BACKWARD' } );
|
|
|
|
|
|
|
+ expectValue( value, expected[ --i ], { direction: 'backward' } );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
expect( i ).to.equal( 0 );
|
|
expect( i ).to.equal( 0 );
|
|
@@ -980,7 +980,7 @@ describe( 'TreeWalker', () => {
|
|
|
function expectValue( value, expected, options = {} ) {
|
|
function expectValue( value, expected, options = {} ) {
|
|
|
let expectedPreviousPosition, expectedNextPosition;
|
|
let expectedPreviousPosition, expectedNextPosition;
|
|
|
|
|
|
|
|
- if ( options.direction == 'BACKWARD' ) {
|
|
|
|
|
|
|
+ if ( options.direction == 'backward' ) {
|
|
|
expectedNextPosition = expected.previousPosition;
|
|
expectedNextPosition = expected.previousPosition;
|
|
|
expectedPreviousPosition = expected.nextPosition;
|
|
expectedPreviousPosition = expected.nextPosition;
|
|
|
} else {
|
|
} else {
|
|
@@ -992,11 +992,11 @@ function expectValue( value, expected, options = {} ) {
|
|
|
expect( value.previousPosition ).to.deep.equal( expectedPreviousPosition );
|
|
expect( value.previousPosition ).to.deep.equal( expectedPreviousPosition );
|
|
|
expect( value.nextPosition ).to.deep.equal( expectedNextPosition );
|
|
expect( value.nextPosition ).to.deep.equal( expectedNextPosition );
|
|
|
|
|
|
|
|
- if ( value.type == 'TEXT' ) {
|
|
|
|
|
|
|
+ if ( value.type == 'text' ) {
|
|
|
expectText( value, expected );
|
|
expectText( value, expected );
|
|
|
- } else if ( value.type == 'ELEMENT_START' ) {
|
|
|
|
|
|
|
+ } else if ( value.type == 'elementStart' ) {
|
|
|
expectStart( value, expected );
|
|
expectStart( value, expected );
|
|
|
- } else if ( value.type == 'ELEMENT_END' ) {
|
|
|
|
|
|
|
+ } else if ( value.type == 'elementEnd' ) {
|
|
|
expectEnd( value, expected );
|
|
expectEnd( value, expected );
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|