From 53139ec35cef71fd2b216040b964daf556f8edc0 Mon Sep 17 00:00:00 2001 From: Xiawei Date: Wed, 10 Mar 2021 19:56:23 +0800 Subject: [PATCH] fix #136 removeRow when skips columns when adjusting rowspan --- src/commands.js | 2 ++ test/test-commands.js | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/commands.js b/src/commands.js index ff7690e1..34b55b06 100644 --- a/src/commands.js +++ b/src/commands.js @@ -183,6 +183,7 @@ export function removeRow(tr, {map, table, tableStart}, row) { let attrs = table.nodeAt(pos).attrs tr.setNodeMarkup(tr.mapping.slice(mapFrom).map(pos + tableStart), null, setAttr(attrs, "rowspan", attrs.rowspan - 1)) col += attrs.colspan - 1 + index += attrs.colspan - 1 } else if (row < map.height && pos == map.map[index + map.width]) { // Else, if it continues in the row below, it has to be moved down let cell = table.nodeAt(pos) @@ -190,6 +191,7 @@ export function removeRow(tr, {map, table, tableStart}, row) { let newPos = map.positionAt(row + 1, col, table) tr.insert(tr.mapping.slice(mapFrom).map(tableStart + newPos), copy) col += cell.attrs.colspan - 1 + index += cell.attrs.colspan - 1 } } } diff --git a/test/test-commands.js b/test/test-commands.js index f3ff06a6..e5392183 100644 --- a/test/test-commands.js +++ b/test/test-commands.js @@ -264,9 +264,14 @@ describe("deleteRow", () => { table(tr(c11, c11)))) it("skips columns when adjusting rowspan", () => - test(table(tr(cCursor, c(2, 2)), tr(c11)), + test(table(tr(cCursor, c(2, 2), c11), tr(c11, c11)), + deleteRow, + table(tr(c11, c(2, 1), c11)))) + + it("skips columns when adjusting rowspan", () => + test(table(tr(c11, c(2, 2), c11), tr(c11, cCursor)), deleteRow, - table(tr(c11, c(2, 1))))) + table(tr(c11, c(2, 1), c11)))) it("can delete a cell selection", () => test(table(tr(cAnchor, c11), tr(c11, cEmpty)),