Skip to content

Commit

Permalink
Make AutoEmptyBlockAncestorDeleter::GetNewCaretPosition always retu…
Browse files Browse the repository at this point in the history
…rn 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
  • Loading branch information
masayuki-nakano authored and moz-wptsync-bot committed Oct 21, 2022
1 parent 35990e5 commit 1db0e4c
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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>

1 comment on commit 1db0e4c

@community-tc-integration
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh oh! Looks like an error! Details

HttpError: You have exceeded a secondary rate limit. Please wait a few minutes before you try again.

Please sign in to comment.