diff --git a/editor/libeditor/HTMLEditRules.cpp b/editor/libeditor/HTMLEditRules.cpp
index 994544926717..5b9ec24ead4b 100644
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -193,6 +193,7 @@ HTMLEditRules::HTMLEditRules()
mListenerEnabled(false),
mReturnInEmptyLIKillsList(false),
mDidDeleteSelection(false),
+ mDidExplicitlySetInterline(false),
mDidRangedDelete(false),
mDidEmptyParentBlocksRemoved(false),
mRestoreContentEditableCount(false),
@@ -206,6 +207,7 @@ void HTMLEditRules::InitFields() {
mDocChangeRange = nullptr;
mReturnInEmptyLIKillsList = true;
mDidDeleteSelection = false;
+ mDidExplicitlySetInterline = false;
mDidRangedDelete = false;
mDidEmptyParentBlocksRemoved = false;
mRestoreContentEditableCount = false;
@@ -3931,11 +3933,12 @@ nsresult HTMLEditRules::DidDeleteSelection() {
}
// call through to base class
- nsresult rv = TextEditRules::DidDeleteSelection();
- if (NS_WARN_IF(NS_FAILED(rv))) {
- return rv;
- }
- return NS_OK;
+ nsresult rv = TextEditRules::DidDeleteSelection(
+ mDidExplicitlySetInterline ? SetSelectionInterLinePosition::No
+ : SetSelectionInterLinePosition::Yes);
+ NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
+ "TextEditRules::DidDeleteSelection() failed");
+ return rv;
}
nsresult HTMLEditRules::WillMakeList(const nsAString* aListType,
diff --git a/editor/libeditor/HTMLEditRules.h b/editor/libeditor/HTMLEditRules.h
index 1b77c8c5d2a2..cc1609db292a 100644
--- a/editor/libeditor/HTMLEditRules.h
+++ b/editor/libeditor/HTMLEditRules.h
@@ -1352,6 +1352,7 @@ class HTMLEditRules : public TextEditRules {
bool mListenerEnabled;
bool mReturnInEmptyLIKillsList;
bool mDidDeleteSelection;
+ bool mDidExplicitlySetInterline;
bool mDidRangedDelete;
bool mDidEmptyParentBlocksRemoved;
bool mRestoreContentEditableCount;
diff --git a/editor/libeditor/TextEditRules.cpp b/editor/libeditor/TextEditRules.cpp
index d51abb077d62..bbefbe1dd1b5 100644
--- a/editor/libeditor/TextEditRules.cpp
+++ b/editor/libeditor/TextEditRules.cpp
@@ -91,14 +91,12 @@ TextEditRules::TextEditRules()
#ifdef DEBUG
mIsHandling(false),
#endif // #ifdef DEBUG
- mDidExplicitlySetInterline(false),
mIsHTMLEditRules(false) {
InitFields();
}
void TextEditRules::InitFields() {
mTextEditor = nullptr;
- mDidExplicitlySetInterline = false;
}
HTMLEditRules* TextEditRules::AsHTMLEditRules() {
@@ -163,8 +161,6 @@ nsresult TextEditRules::BeforeEdit() {
return NS_ERROR_EDITOR_DESTROYED;
}
- mDidExplicitlySetInterline = false;
-
#ifdef DEBUG
mIsHandling = true;
#endif // #ifdef DEBUG
@@ -296,7 +292,8 @@ nsresult TextEditRules::DidDoAction(EditSubActionInfo& aInfo,
switch (aInfo.mEditSubAction) {
case EditSubAction::eDeleteSelectedContent:
- return DidDeleteSelection();
+ MOZ_ASSERT(!mIsHTMLEditRules);
+ return DidDeleteSelection(SetSelectionInterLinePosition::Yes);
case EditSubAction::eInsertElement:
case EditSubAction::eUndo:
case EditSubAction::eRedo:
@@ -783,6 +780,7 @@ nsresult TextEditRules::WillSetText(bool* aCancel, bool* aHandled,
const nsAString* aString,
int32_t aMaxLength) {
MOZ_ASSERT(IsEditorDataAvailable());
+ MOZ_ASSERT(!mIsHTMLEditRules);
MOZ_ASSERT(aCancel);
MOZ_ASSERT(aHandled);
MOZ_ASSERT(aString);
@@ -897,7 +895,8 @@ nsresult TextEditRules::WillSetText(bool* aCancel, bool* aHandled,
// If we replaced non-empty value with empty string, we need to delete the
// text node.
if (tString.IsEmpty()) {
- DebugOnly rvIgnored = DidDeleteSelection();
+ DebugOnly rvIgnored =
+ DidDeleteSelection(SetSelectionInterLinePosition::Yes);
MOZ_ASSERT(rvIgnored != NS_ERROR_EDITOR_DESTROYED);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored),
"DidDeleteSelection() failed");
@@ -1023,7 +1022,8 @@ nsresult TextEditRules::DeleteSelectionWithTransaction(
return NS_OK;
}
-nsresult TextEditRules::DidDeleteSelection() {
+nsresult TextEditRules::DidDeleteSelection(
+ SetSelectionInterLinePosition aSetSelectionInterLinePosition) {
MOZ_ASSERT(IsEditorDataAvailable());
EditorDOMPoint selectionStartPoint(
@@ -1046,7 +1046,7 @@ nsresult TextEditRules::DidDeleteSelection() {
}
}
- if (mDidExplicitlySetInterline) {
+ if (aSetSelectionInterLinePosition != SetSelectionInterLinePosition::Yes) {
return NS_OK;
}
// We prevent the caret from sticking on the left of prior BR
diff --git a/editor/libeditor/TextEditRules.h b/editor/libeditor/TextEditRules.h
index e6e92b2eeab7..4a06904ba34a 100644
--- a/editor/libeditor/TextEditRules.h
+++ b/editor/libeditor/TextEditRules.h
@@ -214,7 +214,12 @@ class TextEditRules {
* This method may remove empty text node and makes guarantee that caret
* is never at left of
element.
*/
- MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult DidDeleteSelection();
+ enum class SetSelectionInterLinePosition {
+ Yes,
+ No,
+ };
+ MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult DidDeleteSelection(
+ SetSelectionInterLinePosition aSetSelectionInterLinePosition);
nsresult WillSetTextProperty(bool* aCancel, bool* aHandled);
@@ -363,7 +368,6 @@ class TextEditRules {
bool mIsHandling;
#endif // #ifdef DEBUG
- bool mDidExplicitlySetInterline;
bool mIsHTMLEditRules;
};