Skip to content

Commit

Permalink
fix #136 removeRow when skips columns when adjusting rowspan
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaweiss committed Mar 10, 2021
1 parent 75b3f0f commit 53139ec
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,15 @@ 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)
let copy = cell.type.create(setAttr(cell.attrs, "rowspan", cell.attrs.rowspan - 1), cell.content)
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
}
}
}
Expand Down
9 changes: 7 additions & 2 deletions test/test-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down

0 comments on commit 53139ec

Please sign in to comment.