Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,31 @@ describe('tables-adapter regressions', () => {
});
});

it('applies table shading to all cells when target is a table', () => {
const editor = makeTableEditor();
const tr = editor.state.tr as unknown as { setNodeMarkup: ReturnType<typeof vi.fn> };

const result = tablesSetShadingAdapter(editor, {
nodeId: 'table-1',
color: 'FFFF00',
});

expect(result.success).toBe(true);

const cellUpdates = tr.setNodeMarkup.mock.calls.filter(
(call) =>
typeof call[2] === 'object' &&
call[2] != null &&
(call[2] as { tableCellProperties?: { shading?: { fill?: string } } }).tableCellProperties?.shading?.fill ===
'FFFF00',
);

expect(cellUpdates).toHaveLength(4);
for (const call of cellUpdates) {
expect((call[2] as { background?: { color?: string } }).background).toEqual({ color: 'FFFF00' });
}
});

it.each([
{
name: 'tables.setBorder',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2596,6 +2596,34 @@ export function tablesSetShadingAdapter(
currentProps.shading = { fill: input.color, val: 'clear', color: 'auto' };
const syncAttrs = resolved.scope === 'table' ? syncExtractedTableAttrs(currentProps) : {};
tr.setNodeMarkup(resolved.pos, null, { ...currentAttrs, [propsKey]: currentProps, ...syncAttrs });

if (resolved.scope === 'table') {
const tableNode = resolved.node;
const tableStart = resolved.pos + 1;
const map = TableMap.get(tableNode);
const seen = new Set<number>();
const mapFrom = tr.mapping.maps.length;

for (let i = 0; i < map.map.length; i++) {
const relPos = map.map[i]!;
if (seen.has(relPos)) continue;
seen.add(relPos);

const cellNode = tableNode.nodeAt(relPos);
if (!cellNode) continue;

const cellAttrs = cellNode.attrs as Record<string, unknown>;
const cellProps = { ...((cellAttrs.tableCellProperties ?? {}) as Record<string, unknown>) };
cellProps.shading = { fill: input.color, val: 'clear', color: 'auto' };

tr.setNodeMarkup(tr.mapping.slice(mapFrom).map(tableStart + relPos), null, {
...cellAttrs,
tableCellProperties: cellProps,
background: { color: input.color },
Comment thread
harbournick marked this conversation as resolved.
Outdated
});
}
}

applyDirectMutationMeta(tr);
editor.dispatch(tr);
clearIndexCache(editor);
Expand Down
Loading