Alex-D / Trumbowyg

A lightweight and amazing WYSIWYG JavaScript editor under 10kB
https://alex-d.github.io/Trumbowyg
MIT License
4.02k stars 614 forks source link

Fixing issue with creation of new table rows #1290

Closed gary-britland closed 1 year ago

gary-britland commented 2 years ago

Currently "Add Row" and "Add Row Above" used the first row in the table to build the new row. This is fine if the table is vanilla and contains the same number of cells throughout all rows for the whole table but in some cases the first row has merged cells utilising "colspan". The current behaviour would only create a row with the same number of cells as the first row and not apply any "colspan" attributes to compensate leaving a broken table. If the first row only contains one cell but the rest of the table contains four each new row added only contains one cell.

With my changes I have used the focus row as the pattern for the new row. Lopping through the cells utilising jQuery.clone() function to ensure each cell is identical to the focus row and then jQuey.text() to clear the cells of any content. This ensures the "colspan" and other attributes are applied correctly. This is the behaviour I believe people are looking for when using the editor as this is the behaviour most table editors use.

Alex-D commented 1 year ago

Thank you :)