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

[visual] Keep bottom border when removing entire last row

GitOrigin-RevId: 27711ffa1f8dffc1af50078b95b3b24e7f00f5fe
This commit is contained in:
Mathias Jakobsen 2023-09-13 09:56:41 +01:00 committed by Copybot
parent 3aa6346ab3
commit e7519be904
2 changed files with 17 additions and 7 deletions

View file

@ -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; ) {

View file

@ -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 () {