diff --git a/editor/libeditor/HTMLEditUtils.h b/editor/libeditor/HTMLEditUtils.h
index dbdce02ecef1..f02c67b4c418 100644
--- a/editor/libeditor/HTMLEditUtils.h
+++ b/editor/libeditor/HTMLEditUtils.h
@@ -1457,17 +1457,8 @@ class HTMLEditUtils final {
return EditorDOMRangeType();
}
return EditorDOMRangeType(
- typename EditorDOMRangeType::PointType(
- firstListItem->GetFirstChild() &&
- firstListItem->GetFirstChild()->IsText()
- ? firstListItem->GetFirstChild()
- : static_cast(firstListItem),
- 0u),
- EditorDOMRangeType::PointType::AtEndOf(
- lastListItem->GetLastChild() &&
- lastListItem->GetLastChild()->IsText()
- ? *lastListItem->GetFirstChild()
- : static_cast(*lastListItem)));
+ typename EditorDOMRangeType::PointType(firstListItem, 0u),
+ EditorDOMRangeType::PointType::AtEndOf(*lastListItem));
}
/**
diff --git a/editor/libeditor/HTMLEditorDeleteHandler.cpp b/editor/libeditor/HTMLEditorDeleteHandler.cpp
index 2ead3acc01a6..784570808432 100644
--- a/editor/libeditor/HTMLEditorDeleteHandler.cpp
+++ b/editor/libeditor/HTMLEditorDeleteHandler.cpp
@@ -3372,6 +3372,14 @@ HTMLEditor::AutoDeleteRangesHandler::HandleDeleteNonCollapsedRanges(
}
if (NS_WARN_IF(aRangesToDelete.FirstRangeRef()->Collapsed())) {
// Hmm, there is nothing to delete...?
+ // In this case, the callers want collapsed selection. Therefore, we need
+ // to change the `Selection` here.
+ nsresult rv = aHTMLEditor.CollapseSelectionTo(
+ aRangesToDelete.GetFirstRangeStartPoint());
+ if (NS_FAILED(rv)) {
+ NS_WARNING("EditorBase::CollapseSelectionTo() failed");
+ return Err(rv);
+ }
return EditActionResult::HandledResult();
}
MOZ_ASSERT(aRangesToDelete.IsFirstRangeEditable(aEditingHost));
diff --git a/testing/web-platform/tests/editing/crashtests/inserthtml-to-replace-root-list-element-in-designMode.html b/testing/web-platform/tests/editing/crashtests/inserthtml-to-replace-root-list-element-in-designMode.html
new file mode 100644
index 000000000000..c751a5bebcdf
--- /dev/null
+++ b/testing/web-platform/tests/editing/crashtests/inserthtml-to-replace-root-list-element-in-designMode.html
@@ -0,0 +1,33 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/testing/web-platform/tests/editing/data/delete.js b/testing/web-platform/tests/editing/data/delete.js
index bbd95e56a260..7e63c518c793 100644
--- a/testing/web-platform/tests/editing/data/delete.js
+++ b/testing/web-platform/tests/editing/data/delete.js
@@ -3012,4 +3012,11 @@ var browserTests = [
"\n- {}
"],
[true],
{}],
+
+// Select all list item children when list items have multiple nodes.
+["{}",
+ [["delete",""]],
+ "",
+ [true],
+ {}],
]
diff --git a/testing/web-platform/tests/editing/data/forwarddelete.js b/testing/web-platform/tests/editing/data/forwarddelete.js
index 7c1218276b22..661b62adb8d1 100644
--- a/testing/web-platform/tests/editing/data/forwarddelete.js
+++ b/testing/web-platform/tests/editing/data/forwarddelete.js
@@ -2892,4 +2892,11 @@ var browserTests = [
"\n- {}
"],
[true],
{}],
+
+// Select all list item children when list items have multiple nodes.
+["{}",
+ [["delete",""]],
+ "",
+ [true],
+ {}],
]