@@ -212,6 +212,111 @@ describe( 'DomConverter', () => {
212212 expect ( viewDiv . getChild ( 1 ) . getChild ( 0 ) . data ) . to . equal ( 'foo' ) ;
213213 } ) ;
214214
215+ it ( 'after a block element' , ( ) => {
216+ const domDiv = createElement ( document , 'div' , { } , [
217+ createElement ( document , 'p' , { } , [
218+ document . createTextNode ( 'foo' )
219+ ] ) ,
220+ document . createTextNode ( ' ' )
221+ ] ) ;
222+
223+ const viewDiv = converter . domToView ( domDiv ) ;
224+
225+ expect ( viewDiv . childCount ) . to . equal ( 1 ) ;
226+ expect ( viewDiv . getChild ( 0 ) . getChild ( 0 ) . data ) . to . equal ( 'foo' ) ;
227+ } ) ;
228+
229+ it ( 'after a block element (new line)' , ( ) => {
230+ const domDiv = createElement ( document , 'div' , { } , [
231+ createElement ( document , 'p' , { } , [
232+ document . createTextNode ( 'foo' )
233+ ] ) ,
234+ document . createTextNode ( '\n' )
235+ ] ) ;
236+
237+ const viewDiv = converter . domToView ( domDiv ) ;
238+
239+ expect ( viewDiv . childCount ) . to . equal ( 1 ) ;
240+ expect ( viewDiv . getChild ( 0 ) . getChild ( 0 ) . data ) . to . equal ( 'foo' ) ;
241+ } ) ;
242+
243+ it ( 'after a block element (carriage return)' , ( ) => {
244+ const domDiv = createElement ( document , 'div' , { } , [
245+ createElement ( document , 'p' , { } , [
246+ document . createTextNode ( 'foo' )
247+ ] ) ,
248+ document . createTextNode ( '\r' )
249+ ] ) ;
250+
251+ const viewDiv = converter . domToView ( domDiv ) ;
252+
253+ expect ( viewDiv . childCount ) . to . equal ( 1 ) ;
254+ expect ( viewDiv . getChild ( 0 ) . getChild ( 0 ) . data ) . to . equal ( 'foo' ) ;
255+ } ) ;
256+
257+ it ( 'after a block element (tab)' , ( ) => {
258+ const domDiv = createElement ( document , 'div' , { } , [
259+ createElement ( document , 'p' , { } , [
260+ document . createTextNode ( 'foo' )
261+ ] ) ,
262+ document . createTextNode ( '\t' )
263+ ] ) ;
264+
265+ const viewDiv = converter . domToView ( domDiv ) ;
266+
267+ expect ( viewDiv . childCount ) . to . equal ( 1 ) ;
268+ expect ( viewDiv . getChild ( 0 ) . getChild ( 0 ) . data ) . to . equal ( 'foo' ) ;
269+ } ) ;
270+
271+ // See https://github.com/ckeditor/ckeditor5-engine/issues/822#issuecomment-311670249
272+ it ( 'but preserve all except " \\n\\r\\t"' , ( ) => {
273+ const domDiv = createElement ( document , 'div' , { } , [
274+ createElement ( document , 'p' , { } , [
275+ document . createTextNode ( 'x\fx\vx\u00a0x\u1680x\u2000x\u200ax\u2028x\u2029x\u202fx\u205fx\u3000x\ufeffx' )
276+ ] ) ,
277+ createElement ( document , 'p' , { } , [
278+ // x<two spaces>x because it behaved differently than "x<space>x" when I've been fixing this
279+ document . createTextNode ( 'x\f\vx\u00a0\u1680x\u2000\u200ax\u2028\u2029x\u202f\u205fx\u3000\ufeffx' )
280+ ] )
281+ ] ) ;
282+
283+ const viewDiv = converter . domToView ( domDiv ) ;
284+
285+ expect ( viewDiv . childCount ) . to . equal ( 2 ) ;
286+ expect ( viewDiv . getChild ( 0 ) . getChild ( 0 ) . data )
287+ . to . equal ( 'x\fx\vx\u00a0x\u1680x\u2000x\u200ax\u2028x\u2029x\u202fx\u205fx\u3000x\ufeffx' ) ;
288+ expect ( viewDiv . getChild ( 1 ) . getChild ( 0 ) . data )
289+ . to . equal ( 'x\f\vx\u00a0\u1680x\u2000\u200ax\u2028\u2029x\u202f\u205fx\u3000\ufeffx' ) ;
290+ } ) ;
291+
292+ it ( 'before a block element' , ( ) => {
293+ const domDiv = createElement ( document , 'div' , { } , [
294+ document . createTextNode ( ' ' ) ,
295+ createElement ( document , 'p' , { } , [
296+ document . createTextNode ( ' foo' )
297+ ] )
298+ ] ) ;
299+
300+ const viewDiv = converter . domToView ( domDiv ) ;
301+
302+ expect ( viewDiv . childCount ) . to . equal ( 1 ) ;
303+ expect ( viewDiv . getChild ( 0 ) . getChild ( 0 ) . data ) . to . equal ( 'foo' ) ;
304+ } ) ;
305+
306+ it ( 'before a block element (new line)' , ( ) => {
307+ const domDiv = createElement ( document , 'div' , { } , [
308+ document . createTextNode ( '\n' ) ,
309+ createElement ( document , 'p' , { } , [
310+ document . createTextNode ( 'foo' )
311+ ] )
312+ ] ) ;
313+
314+ const viewDiv = converter . domToView ( domDiv ) ;
315+
316+ expect ( viewDiv . childCount ) . to . equal ( 1 ) ;
317+ expect ( viewDiv . getChild ( 0 ) . getChild ( 0 ) . data ) . to . equal ( 'foo' ) ;
318+ } ) ;
319+
215320 it ( 'multiple consecutive whitespaces changed to one' , ( ) => {
216321 const domDiv = createElement ( document , 'div' , { } , [
217322 createElement ( document , 'p' , { } , [
@@ -228,6 +333,21 @@ describe( 'DomConverter', () => {
228333 expect ( viewDiv . getChild ( 1 ) . getChild ( 0 ) . data ) . to . equal ( 'fo o' ) ;
229334 } ) ;
230335
336+ it ( 'multiple consecutive whitespaces changed to one (tab, new line, carriage return)' , ( ) => {
337+ const domDiv = createElement ( document , 'div' , { } , [
338+ document . createTextNode ( '\n\n \t\r\n' ) ,
339+ createElement ( document , 'p' , { } , [
340+ document . createTextNode ( 'f\n\t\r\n\to\n\n\no' )
341+ ] ) ,
342+ document . createTextNode ( '\n\n \t\r\n' )
343+ ] ) ;
344+
345+ const viewDiv = converter . domToView ( domDiv ) ;
346+
347+ expect ( viewDiv . childCount ) . to . equal ( 1 ) ;
348+ expect ( viewDiv . getChild ( 0 ) . getChild ( 0 ) . data ) . to . equal ( 'f o o' ) ;
349+ } ) ;
350+
231351 function test ( inputTexts , output ) {
232352 if ( typeof inputTexts == 'string' ) {
233353 inputTexts = [ inputTexts ] ;
@@ -339,6 +459,10 @@ describe( 'DomConverter', () => {
339459
340460 expect ( viewDiv . getChild ( 0 ) . getChild ( 0 ) . data ) . to . equal ( ' foo\n foo ' ) ;
341461 } ) ;
462+
463+ //
464+ // See also whitespace-handling-integration.js.
465+ //
342466 } ) ;
343467 } ) ;
344468
@@ -602,6 +726,8 @@ describe( 'DomConverter', () => {
602726
603727 expect ( viewSelection . rangeCount ) . to . equal ( 1 ) ;
604728 expect ( stringify ( viewP , viewSelection . getFirstRange ( ) ) ) . to . equal ( '<p>f{oo<b>ba}r</b></p>' ) ;
729+
730+ domP . remove ( ) ;
605731 } ) ;
606732
607733 it ( 'should convert empty selection to empty selection' , ( ) => {
@@ -638,6 +764,8 @@ describe( 'DomConverter', () => {
638764 expect ( viewSelection . anchor . offset ) . to . equal ( 2 ) ;
639765 expect ( viewSelection . focus . offset ) . to . equal ( 1 ) ;
640766 expect ( viewSelection . isBackward ) . to . be . true ;
767+
768+ domP . remove ( ) ;
641769 } ) ;
642770
643771 it ( 'should not add null ranges' , ( ) => {
@@ -659,6 +787,8 @@ describe( 'DomConverter', () => {
659787 const viewSelection = converter . domSelectionToView ( domSelection ) ;
660788
661789 expect ( viewSelection . rangeCount ) . to . equal ( 0 ) ;
790+
791+ domP . remove ( ) ;
662792 } ) ;
663793
664794 it ( 'should return fake selection' , ( ) => {
@@ -679,6 +809,8 @@ describe( 'DomConverter', () => {
679809 const bindViewSelection = converter . domSelectionToView ( domSelection ) ;
680810
681811 expect ( bindViewSelection . isEqual ( viewSelection ) ) . to . be . true ;
812+
813+ domContainer . remove ( ) ;
682814 } ) ;
683815
684816 it ( 'should return fake selection if selection is placed inside text node' , ( ) => {
@@ -699,6 +831,8 @@ describe( 'DomConverter', () => {
699831 const bindViewSelection = converter . domSelectionToView ( domSelection ) ;
700832
701833 expect ( bindViewSelection . isEqual ( viewSelection ) ) . to . be . true ;
834+
835+ domContainer . remove ( ) ;
702836 } ) ;
703837 } ) ;
704838} ) ;
0 commit comments