Skip to content

Commit

Permalink
fix: remove column but not minus width in not full table
Browse files Browse the repository at this point in the history
  • Loading branch information
zzxming authored Nov 15, 2024
2 parents df32077 + 66edfa8 commit 5a57e3c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
33 changes: 33 additions & 0 deletions src/__tests__/table-insert-remove-merge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,39 @@ describe('remove column from table', () => {
);
});

it('remove column in not full table', async () => {
const quill = await createTable(1, 3, false, 100);
const tableModule = quill.getModule('tableUp') as TableUp;
await vi.runAllTimersAsync();
const table = quill.root.querySelector('table')!;
tableModule.tableSelection = new TableSelection(tableModule, table, quill);
const tds = quill.scroll.descendants(TableCellInnerFormat, 0);
tableModule.tableSelection.selectedTds = [tds[0]];
tableModule.removeCol();
await vi.runAllTimersAsync();
expect(quill.root).toEqualHTML(
`
<p><br></p>
<div>
<table cellpadding="0" cellspacing="0" style="width: 200px;">
<colgroup>
<col width="100px" />
<col width="100px" />
</colgroup>
<tbody>
<tr>
<td rowspan="1" colspan="1"><div><p>2</p></div></td>
<td rowspan="1" colspan="1"><div><p>3</p></div></td>
</tr>
</tbody>
</table>
</div>
<p><br></p>
`,
{ ignoreAttrs: ['class', 'data-table-id', 'data-row-id', 'data-col-id', 'data-rowspan', 'data-colspan', 'contenteditable'] },
);
});

it('remove column. remove colspan start cell and rowspan cell', async () => {
const quill = createQuillWithTableModule(`<p><br></p>`);
const tableModule = quill.getModule('tableUp') as TableUp;
Expand Down
13 changes: 8 additions & 5 deletions src/formats/table-colgroup-format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,16 @@ export class TableColgroupFormat extends ContainerFormat {
}
const col = this.findCol(index);
if (col) {
if (col.next) {
(col.next as TableColFormat).width += col.width;
}
else if (col.prev) {
(col.prev as TableColFormat).width += col.width;
if (table.full) {
if (col.next) {
(col.next as TableColFormat).width += col.width;
}
else if (col.prev) {
(col.prev as TableColFormat).width += col.width;
}
}
col.remove();
table.colWidthFillTable();
}
}

Expand Down

0 comments on commit 5a57e3c

Please sign in to comment.