diff --git a/src/commands.ts b/src/commands.ts index 2f8a9c70..3356708c 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -294,8 +294,15 @@ export function removeRow( const mapFrom = tr.mapping.maps.length; tr.delete(rowPos + tableStart, nextRow + tableStart); + const seen = new Set(); + for (let col = 0, index = row * map.width; col < map.width; col++, index++) { const pos = map.map[index]; + + // Skip cells that are checked already + if (seen.has(pos)) continue; + seen.add(pos); + if (row > 0 && pos == map.map[index - map.width]) { // If this cell starts in the row above, simply reduce its rowspan const attrs = table.nodeAt(pos)!.attrs as CellAttrs; diff --git a/test/commands.test.ts b/test/commands.test.ts index 36db6aa1..68f1e669 100644 --- a/test/commands.test.ts +++ b/test/commands.test.ts @@ -425,6 +425,13 @@ describe('deleteRow', () => { table(tr(c11, cEmpty)), )); + it('moves the same cell with colspan greater than 1 that start in the deleted row only once', () => + test( + table(tr(c(3, 2), c11, c(2, 2), cCursor), tr(c11, cEmpty)), + deleteRow, + table(tr(c(3, 1), c11, c(2, 1), cEmpty)), + )); + it('deletes multiple rows when the start cell has a rowspan', () => test( table( @@ -437,6 +444,18 @@ describe('deleteRow', () => { table(tr(c11, c11)), )); + it('moves the same cell with colspan greater than 1 that start in the deleted row only once when deleting multiple rows', () => + test( + table( + tr(c(2, 4), td({ rowspan: 3 }, p('')), c11), + tr(c11), + tr(c11), + tr(c11, c11), + ), + deleteRow, + table(tr(c(2, 1), c11, c11)), + )); + it('skips columns when adjusting rowspan', () => test( table(tr(cCursor, c(2, 2)), tr(c11)),