@@ -410,5 +410,66 @@ describe('tableSelectionUtils', () => {
410410 const result = getIsSelectingOrUnselecting ( null , newTableSelection ) ;
411411 expect ( result ) . toBe ( 'selecting' ) ;
412412 } ) ;
413+
414+ it ( 'should work with actual parsed table when lastCo is before firstCo' , ( ) => {
415+ // Create actual table cells with content
416+ const td1 = document . createElement ( 'td' ) ;
417+ td1 . innerText = 'A1' ;
418+ const td2 = document . createElement ( 'td' ) ;
419+ td2 . innerText = 'B1' ;
420+ const td3 = document . createElement ( 'td' ) ;
421+ td3 . innerText = 'C1' ;
422+ const td4 = document . createElement ( 'td' ) ;
423+ td4 . innerText = 'A2' ;
424+ const td5 = document . createElement ( 'td' ) ;
425+ td5 . innerText = 'B2' ;
426+ const td6 = document . createElement ( 'td' ) ;
427+ td6 . innerText = 'C2' ;
428+ const td7 = document . createElement ( 'td' ) ;
429+ td7 . innerText = 'A3' ;
430+ const td8 = document . createElement ( 'td' ) ;
431+ td8 . innerText = 'B3' ;
432+ const td9 = document . createElement ( 'td' ) ;
433+ td9 . innerText = 'C3' ;
434+
435+ const mockTableSelectionInfo : TableSelectionInfo = {
436+ parsedTable : [
437+ [ td1 , td2 , td3 ] ,
438+ [ td4 , td5 , td6 ] ,
439+ [ td7 , td8 , td9 ] ,
440+ ] ,
441+ firstCo : { row : 2 , col : 2 } , // C3
442+ lastCo : { row : 0 , col : 0 } , // A1 - lastCo before firstCo
443+ table : document . createElement ( 'table' ) ,
444+ startNode : td1 ,
445+ } ;
446+
447+ // Test that retrieveStringFromParsedTable works with reversed coordinates
448+ const extractedText = retrieveStringFromParsedTable ( mockTableSelectionInfo ) ;
449+ expect ( extractedText ) . toBe ( ' A1, B1, C1, A2, B2, C2, A3, B3, C3,' ) ;
450+
451+ const prevTableSelection : TableSelection = {
452+ type : 'table' ,
453+ table : document . createElement ( 'table' ) ,
454+ firstRow : 2 ,
455+ firstColumn : 2 ,
456+ lastRow : 0 ,
457+ lastColumn : 0 ,
458+ tableSelectionInfo : mockTableSelectionInfo ,
459+ } ; // 3x3 selection with lastCo before firstCo (area = 9)
460+
461+ const newTableSelection : TableSelection = {
462+ type : 'table' ,
463+ table : document . createElement ( 'table' ) ,
464+ firstRow : 1 ,
465+ firstColumn : 1 ,
466+ lastRow : 1 ,
467+ lastColumn : 1 ,
468+ tableSelectionInfo : mockTableSelectionInfo ,
469+ } ; // Single cell selection (area = 1)
470+
471+ const result = getIsSelectingOrUnselecting ( prevTableSelection , newTableSelection ) ;
472+ expect ( result ) . toBe ( 'unselecting' ) ; // Area decreased from 9 to 1
473+ } ) ;
413474 } ) ;
414475} ) ;
0 commit comments