Forráskód Böngészése

Merge pull request #14804 from overleaf/mj-remove-last-row-table

[visual] Keep bottom border when removing entire last row

GitOrigin-RevId: 27711ffa1f8dffc1af50078b95b3b24e7f00f5fe
Mathias Jakobsen 3 éve
szülő
commit
e7519be904

+ 9 - 1
services/web/frontend/js/features/source-editor/components/table-generator/toolbar/commands.ts

@@ -236,6 +236,7 @@ export const removeRowOrColumns = (
     minY: startRow,
     maxY: endRow,
   } = selection.normalized()
+  const borderTheme = table.getBorderTheme()
   const changes: { from: number; to: number; insert: string }[] = []
   const specification = view.state.sliceDoc(
     positions.columnDeclarations.from,
@@ -259,10 +260,17 @@ export const removeRowOrColumns = (
   for (let row = startRow; row <= endRow; row++) {
     if (selection.isRowSelected(row, table)) {
       const rowPosition = positions.rowPositions[row]
+      let insert = ''
+      if (
+        row === numberOfRows - 1 &&
+        borderTheme === BorderTheme.FULLY_BORDERED
+      ) {
+        insert = '\\hline'
+      }
       changes.push({
         from: rowPosition.from,
         to: rowPosition.to,
-        insert: '',
+        insert,
       })
     } else {
       for (let cell = startCell; cell <= endCell; ) {

+ 8 - 6
services/web/test/frontend/features/source-editor/components/codemirror-editor-table-generator.spec.tsx

@@ -265,10 +265,11 @@ cell 3 & cell 4 \\\\
 
     it('Removes rows and columns', function () {
       mountEditor(`
-\\begin{tabular}{ccc}
-    cell 1 & cell 2 & cell 3 \\\\
-    cell 4 & cell 5 & cell 6 \\\\
-    cell 7 & cell 8 & cell 9 \\\\
+\\begin{tabular}{|c|c|c|}
+    \\hline
+    cell 1 & cell 2 & cell 3 \\\\ \\hline
+    cell 4 & cell 5 & cell 6 \\\\ \\hline
+    cell 7 & cell 8 & cell 9 \\\\ \\hline
 \\end{tabular}
       `)
       checkTable([
@@ -288,12 +289,13 @@ cell 3 & cell 4 \\\\
         ['cell 4', 'cell 6'],
         ['cell 7', 'cell 9'],
       ])
-      cy.get('.row-selector').eq(1).click()
+      cy.get('.row-selector').eq(2).click()
       cy.get('@toolbar').findByLabelText('Delete row or column').click()
       checkTable([
         ['cell 1', 'cell 3'],
-        ['cell 7', 'cell 9'],
+        ['cell 4', 'cell 6'],
       ])
+      checkBordersWithNoMultiColumn([true, true, true], [true, true, true])
     })
 
     it('Removes rows correctly when removing from the left', function () {