Bug 1793865 - Make HTMLEditor::HandleOutdentAtSelectionInternal not return caret point suggestion r=m_kato

It restores `Selection` with `AutoSelectionRestorer` instance created first.
Therefore it does not want the callers (currently, only
`HTMLEditor::HandleOutdentAtSelection` only) change `Selection` after doing it
without special reasons.  Therefore, it shouldn't return last caret point
suggestion which is not a good point to put caret actually.  Then, callers
do not need to handle it as they've never done.

Differential Revision: https://phabricator.services.mozilla.com/D159231
This commit is contained in:
Masayuki Nakano 2022-10-18 06:48:45 +00:00
parent 518297a7d8
commit 7b5c93295e
3 changed files with 41 additions and 6 deletions

View File

@ -74,6 +74,13 @@ class MOZ_STACK_CLASS CaretPoint {
*/
void IgnoreCaretPointSuggestion() const { mHandledCaretPoint = true; }
/**
* When propagating the result, it may not want to the caller modify
* selection. In such case, this can clear the caret point. Use
* IgnoreCaretPointSuggestion() in the caller side instead.
*/
void ForgetCaretPointSuggestion() { mCaretPoint.Clear(); }
bool HasCaretPointSuggestion() const { return mCaretPoint.IsSet(); }
constexpr const EditorDOMPoint& CaretPointRef() const { return mCaretPoint; }
constexpr EditorDOMPoint&& UnwrapCaretPoint() {

View File

@ -5218,10 +5218,9 @@ Result<EditActionResult, nsresult> HTMLEditor::HandleOutdentAtSelection(
// at restoring Selection.
Result<SplitRangeOffFromNodeResult, nsresult> outdentResult =
HandleOutdentAtSelectionInternal(aEditingHost);
MOZ_ASSERT_IF(outdentResult.isOk(),
!outdentResult.inspect().HasCaretPointSuggestion());
if (NS_WARN_IF(Destroyed())) {
if (outdentResult.isOk()) {
outdentResult.inspect().IgnoreCaretPointSuggestion();
}
return Err(NS_ERROR_EDITOR_DESTROYED);
}
if (MOZ_UNLIKELY(outdentResult.isErr())) {
@ -5732,9 +5731,15 @@ HTMLEditor::HandleOutdentAtSelectionInternal(const Element& aEditingHost) {
OutdentPartOfBlock(*indentedParentElement, *firstContentToBeOutdented,
*lastContentToBeOutdented, indentedParentIndentedWith,
aEditingHost);
NS_WARNING_ASSERTION(outdentResult.isOk(),
"HTMLEditor::OutdentPartOfBlock() failed");
return outdentResult;
if (MOZ_UNLIKELY(outdentResult.isErr())) {
NS_WARNING("HTMLEditor::OutdentPartOfBlock() failed");
return outdentResult;
}
// We will restore selection soon. Therefore, callers do not need to restore
// the selection.
SplitRangeOffFromNodeResult unwrappedOutdentResult = outdentResult.unwrap();
unwrappedOutdentResult.ForgetCaretPointSuggestion();
return unwrappedOutdentResult;
}
Result<SplitRangeOffFromNodeResult, nsresult>

View File

@ -0,0 +1,23 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script>
var count = 0;
document.addEventListener("DOMContentLoaded", () => {
document.onselectionchange = () => {
document.execCommand("outdent");
document.execCommand("indent");
document.execCommand("insertHorizontalRule");
if (count++ == 10) {
document.onselectionchange = null;
}
};
find("A");
});
</script>
</head>
<body><isindex contenteditable>
A
</body>
</html>