@@ -46,6 +46,21 @@ function iterateScopedRange( html, opt ) {
46
46
return { html : tools . compatHtml ( sandbox . getOuterHtml ( ) ) , list : results } ;
47
47
}
48
48
49
+ function iterateWithRangeIterator ( ranges , mergeConsequent , rangeIteratorOpts ) {
50
+ var rangesIterator = ranges . createIterator ( ) ,
51
+ range ,
52
+ blockList = [ ] ;
53
+
54
+ while ( range = rangesIterator . getNextRange ( mergeConsequent ) ) {
55
+ var iter = range . createIterator ( ) , block ;
56
+ CKEDITOR . tools . extend ( iter , rangeIteratorOpts , true ) ;
57
+ while ( ( block = iter . getNextParagraph ( ) ) )
58
+ blockList . push ( block . getName ( ) ) ;
59
+ }
60
+
61
+ return blockList ;
62
+ }
63
+
49
64
function checkActiveFilter ( source , opt , results , msg ) {
50
65
var sandbox = doc . getById ( 'sandbox' ) ;
51
66
var range = tools . setHtmlWithRange ( sandbox , source ) [ 0 ] ;
@@ -91,6 +106,52 @@ bender.test( {
91
106
checkRangeIteration ( source , null , [ 'p' ] , output , 'Iteration will yield one single paragraph' ) ;
92
107
} ,
93
108
109
+ // #12178
110
+ 'test iterating over end of line' : function ( ) {
111
+ if ( ! CKEDITOR . env . needsBrFiller )
112
+ assert . ignore ( ) ;
113
+
114
+ var source = '<h1>para1[<br /></h1><p>par]a2</p>' ;
115
+ checkRangeIteration ( source , null , [ 'h1' , 'p' ] , null , 'Iteration will yield heading and paragraph.' ) ;
116
+ } ,
117
+
118
+ // #12178
119
+ 'test iterating over end of line - no bogus br' : function ( ) {
120
+ var source = '<h1>para1[</h1><p>par]a2</p>' ;
121
+ checkRangeIteration ( source , null , [ 'h1' , 'p' ] , null , 'Iteration will yield heading and paragraph.' ) ;
122
+ } ,
123
+
124
+ // #12178
125
+ 'test iterating over start of line' : function ( ) {
126
+ if ( ! CKEDITOR . env . needsBrFiller )
127
+ assert . ignore ( ) ;
128
+
129
+ var source = '<h1>pa[ra1<br /></h1><p>]para2</p>' ;
130
+ checkRangeIteration ( source , null , [ 'h1' , 'p' ] , null , 'Iteration will yield heading and paragraph.' ) ;
131
+ } ,
132
+
133
+ // #12178
134
+ 'test iterating over start of line - no bogus br' : function ( ) {
135
+ var source = '<h1>pa[ra1</h1><p>]para2</p>' ;
136
+ checkRangeIteration ( source , null , [ 'h1' , 'p' ] , null , 'Iteration will yield heading and paragraph.' ) ;
137
+ } ,
138
+
139
+ // #12178
140
+ 'test iterating over start of line 2 - no bogus br' : function ( ) {
141
+ var source = '<h1>pa[ra1</h1><p><b>]para2</b></p>' ;
142
+ checkRangeIteration ( source , null , [ 'h1' , 'p' ] , null , 'Iteration will yield heading and paragraph.' ) ;
143
+ } ,
144
+
145
+ // #12178
146
+ 'test iterating over start of line 2 - no bogus br - rangeIterator' : function ( ) {
147
+ var source = '<h1>pa[ra1</h1><p><b>]para2</b></p>' ;
148
+
149
+ var sandbox = doc . getById ( 'sandbox' ) ,
150
+ ranges = tools . setHtmlWithRange ( sandbox , source ) ;
151
+
152
+ assert . areSame ( 'h1,p' , iterateWithRangeIterator ( ranges ) . join ( ',' ) ) ;
153
+ } ,
154
+
94
155
'test iterating over pseudo block' : function ( ) {
95
156
var source = '<div><p>[paragraph</p>text]</div>' ;
96
157
var output = '<div><p>paragraph</p><p>text</p></div>' ;
@@ -139,31 +200,79 @@ bender.test( {
139
200
} ,
140
201
141
202
// #6728, #4450
203
+ // While this test may seem to be totally broken (why would someone create bookmakrs between <tr> and <td>?)
204
+ // it has a deeper sense. It tests what rangeIterator#getNextRange does.
142
205
'test iterating over table cells (with bookmarks among cells)' : function ( ) {
143
206
var source = '<table><tbody><tr>[<td id="cell1">cell1</td>][<td id="cell2">cell2</td>]</tr></tbody></table>' ,
144
207
output = source . replace ( / \[ | \] | \^ / g, '' ) ;
145
208
146
- var sandbox = doc . getById ( 'sandbox' ) ;
147
- var ranges = tools . setHtmlWithRange ( sandbox , source ) ;
209
+ var sandbox = doc . getById ( 'sandbox' ) ,
210
+ ranges = tools . setHtmlWithRange ( sandbox , source ) ;
148
211
149
- // Create bookmarks by intention .
212
+ // Create bookmarks intentionally .
150
213
var bms = ranges . createBookmarks ( ) ;
151
214
152
- // Check iteration sequence.
153
- var rangeIterator = ranges . createIterator ( ) , range , blockList = [ ] ;
154
- // Merge multiple ranges.
155
- while ( range = rangeIterator . getNextRange ( true ) ) {
156
- var iter = range . createIterator ( ) , block ;
157
- while ( ( block = iter . getNextParagraph ( ) ) )
158
- blockList . push ( block . getName ( ) ) ;
159
- }
215
+ assert . areSame ( 'td,td' , iterateWithRangeIterator ( ranges ) . join ( ',' ) , true ) ;
216
+
217
+ // Just to remove bookmarks.
218
+ ranges . moveToBookmarks ( bms ) ;
160
219
161
- arrayAssert . itemsAreEqual ( [ 'td' , 'td' ] , blockList ) ;
220
+ assert . areSame ( tools . compatHtml ( output ) , tools . compatHtml ( sandbox . getHtml ( ) ) ) ;
221
+ } ,
222
+
223
+ // See above an explanation of this test.
224
+ 'test iterating over table cells (with bookmarks among cells) - do not merge subsequent ranges' : function ( ) {
225
+ var source = '<table><tbody><tr>[<td id="cell1">cell1</td>][<td id="cell2">cell2</td>]</tr></tbody></table>' ,
226
+ output = source . replace ( / \[ | \] | \^ / g, '' ) ;
227
+
228
+ var sandbox = doc . getById ( 'sandbox' ) ,
229
+ ranges = tools . setHtmlWithRange ( sandbox , source ) ;
230
+
231
+ // Create bookmarks intentionally.
232
+ var bms = ranges . createBookmarks ( ) ;
233
+
234
+ assert . areSame ( 'td,td' , iterateWithRangeIterator ( ranges ) . join ( ',' ) ) ;
162
235
163
236
// Just to remove bookmarks.
164
237
ranges . moveToBookmarks ( bms ) ;
165
238
166
- assert . areSame ( tools . compatHtml ( output ) , tools . compatHtml ( sandbox . getHtml ( ) ) ) ;
239
+ assert . areSame ( output , tools . compatHtml ( sandbox . getHtml ( ) ) ) ;
240
+ } ,
241
+
242
+ // #6728, #4450
243
+ 'test iterating over entire table' : function ( ) {
244
+ var source = '[<table><tbody><tr><th>cell1</th><td>cell2</td></tr></tbody></table>]' ,
245
+ output1 = source . replace ( / \[ | \] | \^ / g, '' ) ,
246
+ output2 = '<table><tbody><tr><th><p>cell1</p></th><td><p>cell2</p></td></tr></tbody></table>' ;
247
+
248
+ checkRangeIteration ( source , null , [ 'th' , 'td' ] , output1 , 'Iteration should report table cells' ) ;
249
+ checkRangeIteration ( source , { enforceRealBlocks : 1 } , [ 'p' , 'p' ] , output2 , 'Iteration should establish paragraphs inside table cells' ) ;
250
+ } ,
251
+
252
+ // #6728, #4450
253
+ 'test iterating over entire table - use rangeIterator' : function ( ) {
254
+ var source = '[<table><tbody><tr><th>cell1</th><td>cell2</td></tr></tbody></table>]' ,
255
+ output = source . replace ( / \[ | \] | \^ / g, '' ) ;
256
+
257
+ var sandbox = doc . getById ( 'sandbox' ) ,
258
+ ranges = tools . setHtmlWithRange ( sandbox , source ) ;
259
+
260
+ assert . areSame ( 'th,td' , iterateWithRangeIterator ( ranges , true ) . join ( ',' ) ) ;
261
+
262
+ assert . areSame ( output , tools . compatHtml ( sandbox . getHtml ( ) ) ) ;
263
+ } ,
264
+
265
+ // #6728, #4450
266
+ 'test iterating over entire table - use rangeIterator and enforceRealBlocks' : function ( ) {
267
+ var source = '[<table><tbody><tr><th>cell1</th><td>cell2</td></tr></tbody></table>]' ,
268
+ output = '<table><tbody><tr><th><p>cell1</p></th><td><p>cell2</p></td></tr></tbody></table>' ;
269
+
270
+ var sandbox = doc . getById ( 'sandbox' ) ,
271
+ ranges = tools . setHtmlWithRange ( sandbox , source ) ;
272
+
273
+ assert . areSame ( 'p,p' , iterateWithRangeIterator ( ranges , true , { enforceRealBlocks : true } ) . join ( ',' ) ) ;
274
+
275
+ assert . areSame ( output , tools . compatHtml ( sandbox . getHtml ( ) ) ) ;
167
276
} ,
168
277
169
278
'test iterating over list items' : function ( ) {
0 commit comments