diff --git a/editor/libeditor/HTMLTableEditor.cpp b/editor/libeditor/HTMLTableEditor.cpp
index 3c7f140e5e87..e6cd7211672c 100644
--- a/editor/libeditor/HTMLTableEditor.cpp
+++ b/editor/libeditor/HTMLTableEditor.cpp
@@ -217,8 +217,8 @@ HTMLEditor::InsertTableCellsWithTransaction(int32_t aNumberOfCellsToInsert,
newCellIndex = cellDataAtSelection.mCurrent.mColumn;
break;
case InsertPosition::eAfterSelectedCell:
- newCellIndex =
- cellDataAtSelection.mCurrent.mColumn + cellDataAtSelection.mColSpan;
+ MOZ_ASSERT(!cellDataAtSelection.IsSpannedFromOtherRowOrColumn());
+ newCellIndex = cellDataAtSelection.NextColumnIndex();
break;
default:
MOZ_ASSERT_UNREACHABLE("Invalid InsertPosition");