Make `AutoEmptyBlockAncestorDeleter::GetNewCaretPosition` always return a valid point if succeeded
The testcase is tricky. It creates 2 `Selection` ranges, one is collapsed at
end of the `<html>`, the other is collapsed in the new `<h3>` element. The
first one is ignored by delete handler since Gecko does not allow to edit
outside `<body>` for now.
Then, deleting non-collapsed selection ranges tries to delete empty parent
blocks at the remaining collapsed selection range in the `<h3>`. At this time,
it works with `nsIEditor::eNone`. Then, its `GetNewCaretPosition` does not
return a valid point. Then, the `Run` does not remove the `Selection` range
outside the `<body>`.
Therefore, `HTMLEditor::DeleteSelectionAndPrepareToCreateNode()` will see
2 ranges, then, hit the assertion.
Although there are some other cases which meet 2 or more `Selection` ranges
after deletion in `DeleteSelectionAndPrepareToCreateNode`, but for now, we
should make `AutoEmptyBlockAncestorDeleter::Run` collapse `Selection` when
it deletes empty ancestors.
Differential Revision: https://phabricator.services.mozilla.com/D159581
bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1699256
gecko-commit: c3323ac610b4b181872b46030ff084d5f6d6023a
gecko-reviewers: m_kato
diff --git a/editing/crashtests/inserthorizontalrule-with-2-selection-ranges-and-one-is-outside-body.html b/editing/crashtests/inserthorizontalrule-with-2-selection-ranges-and-one-is-outside-body.html
new file mode 100644
index 0000000..d248c33
--- /dev/null
+++ b/editing/crashtests/inserthorizontalrule-with-2-selection-ranges-and-one-is-outside-body.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<script>
+document.addEventListener('DOMContentLoaded', () => {
+ const form = document.createElement("form");
+ const range = new Range();
+ document.documentElement.contentEditable = true;
+ document.execCommand("formatBlock", false, "h3");
+ document.documentElement.appendChild(form);
+ range.setStartBefore(form);
+ getSelection().addRange(range);
+ range.selectNode(form);
+ document.execCommand("insertHorizontalRule");
+});
+</script>
+</head>
+</html>