From 66edfa8634b81ba575eaeedd4c8acd471f284908 Mon Sep 17 00:00:00 2001 From: zzxming Date: Thu, 14 Nov 2024 22:01:52 +0800 Subject: [PATCH] fix: remove column but not minus width in not full table --- .../table-insert-remove-merge.test.ts | 33 +++++++++++++++++++ src/formats/table-colgroup-format.ts | 13 +++++--- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/__tests__/table-insert-remove-merge.test.ts b/src/__tests__/table-insert-remove-merge.test.ts index 41e033a..3e11146 100644 --- a/src/__tests__/table-insert-remove-merge.test.ts +++ b/src/__tests__/table-insert-remove-merge.test.ts @@ -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( + ` +


+
+ + + + + + + + + + + +

2

3

+
+


+ `, + { 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(`


`); const tableModule = quill.getModule('tableUp') as TableUp; diff --git a/src/formats/table-colgroup-format.ts b/src/formats/table-colgroup-format.ts index 16dd738..d4a8b96 100644 --- a/src/formats/table-colgroup-format.ts +++ b/src/formats/table-colgroup-format.ts @@ -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(); } }