Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There is a mistake in the function named addRow #185

Open
weijia18 opened this issue Oct 23, 2022 · 0 comments
Open

There is a mistake in the function named addRow #185

weijia18 opened this issue Oct 23, 2022 · 0 comments

Comments

@weijia18
Copy link
Contributor

weijia18 commented Oct 23, 2022

hi, I find there is a mistake in the function named addRow when I read the source code.

export function addRow(tr, { map, tableStart, table }, row) { let rowPos = tableStart; for (let i = 0; i < row; i++) rowPos += table.child(i).nodeSize; let cells = [], refRow = row > 0 ? -1 : 0; if (rowIsHeader(map, table, row + refRow)) refRow = row == 0 || row == map.height ? null : 0; for (let col = 0, index = map.width * row; col < map.width; col++, index++) { // Covered by a rowspan cell if ( row > 0 && row < map.height && map.map[index] == map.map[index - map.width] ) { let pos = map.map[index], attrs = table.nodeAt(pos).attrs; tr.setNodeMarkup( tableStart + pos, null, setAttr(attrs, 'rowspan', attrs.rowspan + 1), ); col += attrs.colspan - 1; } else { let type = refRow == null ? tableNodeTypes(table.type.schema).cell : table.nodeAt(map.map[index + refRow * map.width]).type; cells.push(type.createAndFill()); } } tr.insert(rowPos, tableNodeTypes(table.type.schema).row.create(null, cells)); return tr; }

the variable of col in the loop may not step by 1 beacuse of col += attrs.colspan - 1;, which cause a mistake that the variable of index is not equel to map.width and the array of cells may miss some cells when the loop is finished. Fortunately,the function of fixTables fix this mistake when dispathing tr.
this function should be like the code below
export function addRow(tr, { map, tableStart, table }, row) { let rowPos = tableStart; for (let i = 0; i < row; i++) rowPos += table.child(i).nodeSize; let cells = [], refRow = row > 0 ? -1 : 0; if (rowIsHeader(map, table, row + refRow)) refRow = row == 0 || row == map.height ? null : 0; for (let col = 0, index = map.width * row; col < map.width; col++) { // Covered by a rowspan cell if ( row > 0 && row < map.height && map.map[index + col] == map.map[index + col - map.width] ) { let pos = map.map[index + col], attrs = table.nodeAt(pos).attrs; tr.setNodeMarkup( tableStart + pos, null, setAttr(attrs, 'rowspan', attrs.rowspan + 1), ); col += attrs.colspan - 1; } else { let type = refRow == null ? tableNodeTypes(table.type.schema).cell : table.nodeAt(map.map[index + col + refRow * map.width]).type; cells.push(type.createAndFill()); } } tr.insert(rowPos, tableNodeTypes(table.type.schema).row.create(null, cells)); return tr; }
could I lunch a merge request to this project?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant