Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix an incorrect math in deleteRow when moving cells #214

Merged
merged 2 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ export function removeRow(
rowspan: attrs.rowspan - 1,
});
col += attrs.colspan - 1;
} else if (row < map.width && pos == map.map[index + map.width]) {
} 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
const cell = table.nodeAt(pos)!;
const attrs = cell.attrs as CellAttrs;
Expand Down
21 changes: 19 additions & 2 deletions test/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,12 +418,29 @@ describe('deleteRow', () => {
table(tr(c11, c11, c(1, 2)), tr(c11, c11)),
));

it('can move cells that start in the deleted row', () =>
it('can move cells that start in the deleted row', () => {
test(
table(tr(c(1, 2), cCursor), tr(cEmpty)),
deleteRow,
table(tr(c11, cEmpty)),
));
);

test(
table(
tr(td({ rowspan: 3 }, p('<cursor>')), c11),
tr(/* */ c11),
tr(/* */ c(1, 3)),
tr(c11 /* */),
tr(c11 /* */),
),
deleteRow,
table(
//
tr(c11, c(1, 2)),
tr(c11 /* */),
),
);
});

it('moves the same cell with colspan greater than 1 that start in the deleted row only once', () =>
test(
Expand Down
Loading