Skip to content

Commit

Permalink
Add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mati365 committed Dec 30, 2024
1 parent 4e43749 commit 9fd88c0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/ckeditor5-table/src/tableselection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,9 @@ export default class TableSelection extends Plugin {
// If the entire last row is selected, extend the selection to include all columns in the rows above for better UX.
// This prevents a scenario where selecting the entire last row (which may contain colspans) results in only one column
// being selected in the row above, instead of all columns (when colspan is equal to the total amount of columns in the table).
// This adjustment is only active for top-left to bottom-right selections.
// This adjustment is only active for top-left to bottom-right selections, as it mimic the behavior of colspan in tables.
// See: https://github.com/ckeditor/ckeditor5/issues/17538
if ( !startColumn && startLocation.row <= endLocation.row ) {
if ( startLocation.row <= endLocation.row ) {
// Pick total width of the last selection row. It includes colspan values and not-fully selected cells.
const totalRowWidth = getTotalColumnsInRow( table, endRow );

Expand Down
22 changes: 22 additions & 0 deletions packages/ckeditor5-table/tests/tableselection.js
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,28 @@ describe( 'TableSelection', () => {
expect( selection.isBackward ).to.be.true;
} );

it( 'should select all cells when selecting from a regular row to a row with colspan', () => {
setModelData( model, modelTable( [
[ '00', '01', '02' ],
[ { contents: '11', colspan: 3 } ]
] ) );

table = modelRoot.getChild( 0 );

const anchorCell = table.getChild( 0 ).getChild( 0 );
const targetCell = table.getChild( 1 ).getChild( 0 );

tableSelection.setCellSelection( anchorCell, targetCell );

const selectedCells = tableSelection.getSelectedTableCells();

expect( selectedCells ).to.have.length( 4 );
expect( selectedCells[ 0 ] ).to.equal( table.getChild( 0 ).getChild( 0 ) );
expect( selectedCells[ 1 ] ).to.equal( table.getChild( 0 ).getChild( 1 ) );
expect( selectedCells[ 2 ] ).to.equal( table.getChild( 0 ).getChild( 2 ) );
expect( selectedCells[ 3 ] ).to.equal( table.getChild( 1 ).getChild( 0 ) );
} );

function assertSelection( anchorCell, focusCell, count ) {
const cells = [ ...selection.getRanges() ].map( range => range.getContainedElement() );

Expand Down

0 comments on commit 9fd88c0

Please sign in to comment.