From 86ae9bb8ab4a840975f05aac8c1e4641e7c8bb15 Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Wed, 13 Nov 2024 08:17:03 +0000 Subject: [PATCH] Bug 1930050 - Make `AutoRangeArray` check the container type r=m_kato, a=dmeehan Differential Revision: https://phabricator.services.mozilla.com/D228624 --- editor/libeditor/AutoRangeArray.cpp | 2 ++ editor/libeditor/EditorDOMPoint.h | 5 +++++ .../formatblock-when-root-is-editing-host.html | 16 ++++++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 testing/web-platform/tests/editing/crashtests/formatblock-when-root-is-editing-host.html diff --git a/editor/libeditor/AutoRangeArray.cpp b/editor/libeditor/AutoRangeArray.cpp index 57b9b26a3546..782ceaf00bb5 100644 --- a/editor/libeditor/AutoRangeArray.cpp +++ b/editor/libeditor/AutoRangeArray.cpp @@ -665,6 +665,7 @@ GetPointAtFirstContentOfLineOrParentHTMLBlockIfFirstContentOfBlock( // If we're formatting a block, we should reformat first ancestor format // block. if (aEditSubAction == EditSubAction::eFormatBlockForHTMLCommand && + point.IsContainerElement() && HTMLEditUtils::IsFormatElementForFormatBlockCommand( *point.ContainerAs())) { point.Set(point.GetContainer()); @@ -836,6 +837,7 @@ static EditorDOMPoint GetPointAfterFollowingLineBreakOrAtFollowingHTMLBlock( // If we're formatting a block, we should reformat first ancestor format // block. if (aEditSubAction == EditSubAction::eFormatBlockForHTMLCommand && + point.IsContainerElement() && HTMLEditUtils::IsFormatElementForFormatBlockCommand( *point.ContainerAs())) { point.SetAfter(point.GetContainer()); diff --git a/editor/libeditor/EditorDOMPoint.h b/editor/libeditor/EditorDOMPoint.h index 907b02f059e1..2f5d35ed6eff 100644 --- a/editor/libeditor/EditorDOMPoint.h +++ b/editor/libeditor/EditorDOMPoint.h @@ -278,6 +278,11 @@ class EditorDOMPointBase final { return mParent && mParent->IsInNativeAnonymousSubtree(); } + /** + * Returns true if the container node is an element node. + */ + bool IsContainerElement() const { return mParent && mParent->IsElement(); } + /** * IsContainerHTMLElement() returns true if the container node is an HTML * element node and its node name is aTag. diff --git a/testing/web-platform/tests/editing/crashtests/formatblock-when-root-is-editing-host.html b/testing/web-platform/tests/editing/crashtests/formatblock-when-root-is-editing-host.html new file mode 100644 index 000000000000..b888b897bbc8 --- /dev/null +++ b/testing/web-platform/tests/editing/crashtests/formatblock-when-root-is-editing-host.html @@ -0,0 +1,16 @@ + + + + + + + +text + \ No newline at end of file