diff --git a/editor/libeditor/EditorBase.cpp b/editor/libeditor/EditorBase.cpp index 285a663b09c6..bb647885931c 100644 --- a/editor/libeditor/EditorBase.cpp +++ b/editor/libeditor/EditorBase.cpp @@ -5211,6 +5211,23 @@ NS_IMETHODIMP EditorBase::GetPasswordMask(nsAString& aPasswordMask) { return NS_OK; } +void EditorBase::UndefineCaretBidiLevel() const { + MOZ_ASSERT(IsEditActionDataAvailable()); + + /** + * After inserting text the caret Bidi level must be set to the level of the + * inserted text.This is difficult, because we cannot know what the level is + * until after the Bidi algorithm is applied to the whole paragraph. + * + * So we set the caret Bidi level to UNDEFINED here, and the caret code will + * set it correctly later + */ + nsFrameSelection* frameSelection = SelectionRefPtr()->GetFrameSelection(); + if (frameSelection) { + frameSelection->UndefineCaretBidiLevel(); + } +} + /****************************************************************************** * EditorBase::AutoSelectionRestorer *****************************************************************************/ diff --git a/editor/libeditor/EditorBase.h b/editor/libeditor/EditorBase.h index 705e72fe5b3b..adbedb0cee17 100644 --- a/editor/libeditor/EditorBase.h +++ b/editor/libeditor/EditorBase.h @@ -2035,6 +2035,12 @@ class EditorBase : public nsIEditor, */ void HideCaret(bool aHide); + protected: // Edit sub-action handler + /** + * UndefineCaretBidiLevel() resets bidi level of the caret. + */ + void UndefineCaretBidiLevel() const; + protected: // Called by helper classes. /** * OnStartToHandleTopLevelEditSubAction() is called when diff --git a/editor/libeditor/HTMLEditRules.cpp b/editor/libeditor/HTMLEditRules.cpp index aa0295cbb3e0..7172e318df5a 100644 --- a/editor/libeditor/HTMLEditRules.cpp +++ b/editor/libeditor/HTMLEditRules.cpp @@ -767,12 +767,12 @@ nsresult HTMLEditRules::WillDoAction(EditSubActionInfo& aInfo, bool* aCancel, switch (aInfo.mEditSubAction) { case EditSubAction::eInsertText: case EditSubAction::eInsertTextComingFromIME: - UndefineCaretBidiLevel(); + TextEditorRef().UndefineCaretBidiLevel(); return MOZ_KnownLive(HTMLEditorRef()) .WillInsertText(aInfo.mEditSubAction, aCancel, aHandled, aInfo.inString, aInfo.outString, aInfo.maxLength); case EditSubAction::eInsertParagraphSeparator: { - UndefineCaretBidiLevel(); + TextEditorRef().UndefineCaretBidiLevel(); EditActionResult result = WillInsertParagraphSeparator(); if (NS_WARN_IF(result.Failed())) { return result.Rv(); diff --git a/editor/libeditor/TextEditRules.cpp b/editor/libeditor/TextEditRules.cpp index 1d53b04caecb..bdc0d397e529 100644 --- a/editor/libeditor/TextEditRules.cpp +++ b/editor/libeditor/TextEditRules.cpp @@ -203,7 +203,7 @@ nsresult TextEditRules::WillDoAction(EditSubActionInfo& aInfo, bool* aCancel, // my kingdom for dynamic cast switch (aInfo.mEditSubAction) { case EditSubAction::eInsertLineBreak: { - UndefineCaretBidiLevel(); + TextEditorRef().UndefineCaretBidiLevel(); EditActionResult result = WillInsertLineBreak(aInfo.maxLength); if (NS_WARN_IF(result.Failed())) { return result.Rv(); @@ -215,11 +215,11 @@ nsresult TextEditRules::WillDoAction(EditSubActionInfo& aInfo, bool* aCancel, } case EditSubAction::eInsertText: case EditSubAction::eInsertTextComingFromIME: - UndefineCaretBidiLevel(); + TextEditorRef().UndefineCaretBidiLevel(); return WillInsertText(aInfo.mEditSubAction, aCancel, aHandled, aInfo.inString, aInfo.outString, aInfo.maxLength); case EditSubAction::eSetText: - UndefineCaretBidiLevel(); + TextEditorRef().UndefineCaretBidiLevel(); return WillSetText(aCancel, aHandled, aInfo.inString, aInfo.maxLength); case EditSubAction::eDeleteSelectedContent: return WillDeleteSelection(aInfo.collapsedAction, aCancel, aHandled); diff --git a/editor/libeditor/TextEditRules.h b/editor/libeditor/TextEditRules.h index 4164830b0c41..9b9e926dacfb 100644 --- a/editor/libeditor/TextEditRules.h +++ b/editor/libeditor/TextEditRules.h @@ -249,8 +249,6 @@ class TextEditRules { nsAString* aOutString, int32_t aMaxLength, bool* aTruncated); - void UndefineCaretBidiLevel(); - nsresult CheckBidiLevelForDeletion(const EditorRawDOMPoint& aSelectionPoint, nsIEditor::EDirection aAction, bool* aCancel); diff --git a/editor/libeditor/TextEditRulesBidi.cpp b/editor/libeditor/TextEditRulesBidi.cpp index ad2149d8fc68..abdc5cb997b2 100644 --- a/editor/libeditor/TextEditRulesBidi.cpp +++ b/editor/libeditor/TextEditRulesBidi.cpp @@ -82,22 +82,4 @@ nsresult TextEditRules::CheckBidiLevelForDeletion( return NS_OK; } -void TextEditRules::UndefineCaretBidiLevel() { - MOZ_ASSERT(IsEditorDataAvailable()); - - /** - * After inserting text the caret Bidi level must be set to the level of the - * inserted text.This is difficult, because we cannot know what the level is - * until after the Bidi algorithm is applied to the whole paragraph. - * - * So we set the caret Bidi level to UNDEFINED here, and the caret code will - * set it correctly later - */ - RefPtr frameSelection = - SelectionRefPtr()->GetFrameSelection(); - if (frameSelection) { - frameSelection->UndefineCaretBidiLevel(); - } -} - } // namespace mozilla