Skip to content

Commit

Permalink
fix: script error occurs when pasting into table using table-merged-c…
Browse files Browse the repository at this point in the history
…ell (fix #1249) (#1250)
  • Loading branch information
seonim-ryu authored Nov 3, 2020
1 parent 749a048 commit f0caaac
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions plugins/table-merged-cell/src/js/wwMergedTableManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,10 @@ export function getWwMergedTableManager(editor) {
if (selectedCells.length === 1) {
startCell = selectedCells[0];
} else {
startCell = this.wwe.getEditor().getSelection().startContainer;
const { startContainer } = this.wwe.getEditor().getSelection();

startCell =
startContainer.nodeType === Node.TEXT_NODE ? startContainer.parentNode : startContainer;
}

return startCell;
Expand Down Expand Up @@ -352,18 +355,21 @@ export function getWwMergedTableManager(editor) {
_bookmarkLastTd({ rowIndex: endRowIndex, colIndex: endColIndex }) {
const sq = this.wwe.getEditor();
const bookmarkedTable = sq.getBody().querySelector(`.${PASTE_TABLE_BOOKMARK}`);
const tableData = tableDataHandler.createTableData(bookmarkedTable);
const lastCellData = tableData[endRowIndex][endColIndex];

endRowIndex = isExisty(lastCellData.rowMergeWith) ? lastCellData.rowMergeWith : endRowIndex;
endColIndex = isExisty(lastCellData.colMergeWith) ? lastCellData.colMergeWith : endColIndex;
if (bookmarkedTable) {
const tableData = tableDataHandler.createTableData(bookmarkedTable);
const lastCellData = tableData[endRowIndex][endColIndex];

endRowIndex = isExisty(lastCellData.rowMergeWith) ? lastCellData.rowMergeWith : endRowIndex;
endColIndex = isExisty(lastCellData.colMergeWith) ? lastCellData.colMergeWith : endColIndex;

const lastCellIndex = tableData[endRowIndex][endColIndex].elementIndex;
const foundTr = bookmarkedTable.querySelectorAll('tr')[lastCellIndex.rowIndex];
const lastTd = foundTr.children[lastCellIndex.colIndex];
const lastCellIndex = tableData[endRowIndex][endColIndex].elementIndex;
const foundTr = bookmarkedTable.querySelectorAll('tr')[lastCellIndex.rowIndex];
const lastTd = foundTr.children[lastCellIndex.colIndex];

removeClass(bookmarkedTable, PASTE_TABLE_BOOKMARK);
addClass(lastTd, PASTE_TABLE_CELL_BOOKMARK);
removeClass(bookmarkedTable, PASTE_TABLE_BOOKMARK);
addClass(lastTd, PASTE_TABLE_CELL_BOOKMARK);
}
}

/**
Expand Down

0 comments on commit f0caaac

Please sign in to comment.