From 487ff798cd15a4d6d8a2d3356ec34d73f9d2bb74 Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Fri, 9 May 2025 06:46:53 +0000 Subject: [PATCH] Bug 1964011 - part 3: Make `operator<<` overload for `EditorDOMPointeBase` export a few characters of container iif the container is a `Text` r=m_kato This helps to distinguish which the instance points a `Text`. Depends on D248369 Differential Revision: https://phabricator.services.mozilla.com/D248370 --- editor/libeditor/EditorDOMPoint.h | 19 +++++++++++++++++-- editor/libeditor/HTMLEditSubActionHandler.cpp | 2 +- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/editor/libeditor/EditorDOMPoint.h b/editor/libeditor/EditorDOMPoint.h index af4138625960..a6053b4d9c69 100644 --- a/editor/libeditor/EditorDOMPoint.h +++ b/editor/libeditor/EditorDOMPoint.h @@ -23,8 +23,10 @@ #include "nsGkAtoms.h" #include "nsIContent.h" #include "nsINode.h" +#include "nsString.h" #include "nsStyledElement.h" +#include #include namespace mozilla { @@ -1314,8 +1316,21 @@ class EditorDOMPointBase final { const SelfType& aDOMPoint) { aStream << "{ mParent=" << aDOMPoint.GetContainer(); if (aDOMPoint.mParent) { - aStream << " (" << *aDOMPoint.mParent - << ", Length()=" << aDOMPoint.mParent->Length() << ")"; + const auto* parentAsText = dom::Text::FromNode(aDOMPoint.mParent); + if (parentAsText && parentAsText->TextDataLength()) { + nsAutoString data; + parentAsText->AppendTextTo(data); + aStream << " (" << *parentAsText << ", (begins with=\"" + << NS_ConvertUTF16toUTF8( + Substring( + data, + std::min(static_cast(data.Length()), 5u))) + .get() + << "\"), Length()=" << parentAsText->TextDataLength() << ")"; + } else { + aStream << " (" << *aDOMPoint.mParent + << ", Length()=" << aDOMPoint.mParent->Length() << ")"; + } } aStream << ", mChild=" << static_cast(aDOMPoint.mChild); if (aDOMPoint.mChild) { diff --git a/editor/libeditor/HTMLEditSubActionHandler.cpp b/editor/libeditor/HTMLEditSubActionHandler.cpp index a6a873247f63..20743e60c55e 100644 --- a/editor/libeditor/HTMLEditSubActionHandler.cpp +++ b/editor/libeditor/HTMLEditSubActionHandler.cpp @@ -1146,7 +1146,7 @@ Result HTMLEditor::HandleInsertText( } } - auto pointToInsert = [&]() -> EditorDOMPoint { + EditorDOMPoint pointToInsert = [&]() { if (InsertingTextForExtantComposition(aPurpose)) { auto compositionStartPoint = GetFirstIMESelectionStartPoint();