Skip to content

Commit

Permalink
Fixed Table dragging creates an issue #1128
Browse files Browse the repository at this point in the history
Issue: #1128
  • Loading branch information
xdan committed Jun 2, 2024
1 parent 0042c5b commit 70ae1ea
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

### :bug: Bug Fix

- [Table dragging creates an issue #1128](https://github.com/xdan/jodit/issues/1128)
- AddNewLine plugin shown incorrect position after CleanHTML plugin
- Inserting a new table - added extra spaces before the table
- When merging multiple table cells after the TR tag, the CleanHTML plugin added `<br>`
Expand Down
46 changes: 44 additions & 2 deletions src/modules/table/table.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright (c) 2013-2024 Valeriy Chupurnov. All rights reserved. https://xdsoft.net
*/

describe.only('Tables Jodit Editor Tests', () => {
describe('Tables Jodit Editor Tests', () => {
describe('Methods', () => {
it('After init container must have one element .jodit-table-resizer', () => {
const editor = getJodit();
Expand Down Expand Up @@ -255,7 +255,11 @@ describe.only('Tables Jodit Editor Tests', () => {

editor
.getInstance(Jodit.modules.Table)
.appendColumn(editor.editor.firstChild);
.appendColumn(
editor.editor.firstChild,
editor.editor.querySelectorAll('td')[1],
true
);

await waitingForEvent(editor, 'finishedCleanHTMLWorker');

Expand Down Expand Up @@ -535,6 +539,44 @@ describe.only('Tables Jodit Editor Tests', () => {
'</table>',
2,
false
],
[
'<table>' +
'<tbody>' +
'<tr>' +
'<td>1</td>' +
'</tr>' +
'</tbody>' +
'</table>',
'<table>' +
'<tbody>' +
'<tr>' +
'<td><br></td>' +
'<td>1</td>' +
'</tr>' +
'</tbody>' +
'</table>',
0,
false
],
[
'<table>' +
'<tbody>' +
'<tr>' +
'<td>1</td>' +
'</tr>' +
'</tbody>' +
'</table>',
'<table>' +
'<tbody>' +
'<tr>' +
'<td>1</td>' +
'<td><br></td>' +
'</tr>' +
'</tbody>' +
'</table>',
0,
true
]
].forEach(([value, result, column, after], index) => {
describe(`Case #${index} Value is ${value} and column is ${column} and after is ${after}`, () => {
Expand Down
10 changes: 9 additions & 1 deletion src/modules/table/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,18 @@ export class Table extends ViewComponent<IJodit> {
appendColumn(
table: HTMLTableElement,
selectedCell: HTMLTableCellElement,
insertAfter: boolean
insertAfter: boolean = true
): void {
const box = Table.__formalMatrix(table);

if (!insertAfter && Dom.isCell(selectedCell.previousElementSibling)) {
return this.appendColumn(
table,
selectedCell.previousElementSibling as HTMLTableCellElement,
true
);
}

const columnIndex = insertAfter
? selectedCell.cellIndex + ((selectedCell.colSpan || 1) - 1)
: selectedCell.cellIndex;
Expand Down

0 comments on commit 70ae1ea

Please sign in to comment.