[tbb-commits] [tor-browser] 59/73: Bug 1785801 - Make `RangeUpdater::SelAdjJoinNodes` take the ex-offset of right node. r=m_kato, a=RyanVM

gitolite role git at cupani.torproject.org
Wed Sep 21 20:17:52 UTC 2022


This is an automated email from the git hooks/post-receive script.

richard pushed a commit to branch geckoview-102.3.0esr-12.0-1
in repository tor-browser.

commit d902453efafea1b7d63ad3366d8db1c6775f365c
Author: Masayuki Nakano <masayuki at d-toybox.com>
AuthorDate: Fri Sep 2 06:29:36 2022 +0000

    Bug 1785801 - Make `RangeUpdater::SelAdjJoinNodes` take the ex-offset of right node. r=m_kato, a=RyanVM
    
    In bug 1739524, I misunderstood the meaning of `aOffset` of `SelAdjJoinNodes`.
    
    After joining 2 nodes, and a point points right node which will have ex-left
    node content, the point needs to point ex-start of the right node to keep
    next insertion point as-is.  Therefore, it's not useful with new join nodes
    direction, it needs to know the ex-offset of the right node.
    
    This is a backport patch of https://phabricator.services.mozilla.com/D155438 for
    ESR 102.
    
    Differential Revision: https://phabricator.services.mozilla.com/D156271
---
 editor/libeditor/HTMLEditor.cpp                       |  8 ++++----
 editor/libeditor/SelectionState.cpp                   | 14 +++++++-------
 editor/libeditor/SelectionState.h                     |  6 +++---
 testing/web-platform/tests/editing/data/inserttext.js |  6 ++++++
 4 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/editor/libeditor/HTMLEditor.cpp b/editor/libeditor/HTMLEditor.cpp
index 822203e3c9773..d3a277633e45b 100644
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -4939,8 +4939,8 @@ nsresult HTMLEditor::DoJoinNodes(nsIContent& aContentToKeep,
   MOZ_ASSERT(IsEditActionDataAvailable());
 
   const uint32_t removingContentLength = aContentToRemove.Length();
-  const Maybe<uint32_t> removingContentIndex =
-      aContentToRemove.ComputeIndexInParentNode();
+  const Maybe<uint32_t> keepingContentExIndex =
+      aContentToKeep.ComputeIndexInParentNode();
 
   // Remember all selection points.
   // XXX Do we need to restore all types of selections by ourselves?  Normal
@@ -5055,11 +5055,11 @@ nsresult HTMLEditor::DoJoinNodes(nsIContent& aContentToKeep,
     }
   }
 
-  if (MOZ_LIKELY(removingContentIndex.isSome())) {
+  if (MOZ_LIKELY(keepingContentExIndex.isSome())) {
     DebugOnly<nsresult> rvIgnored = RangeUpdaterRef().SelAdjJoinNodes(
         EditorRawDOMPoint(&aContentToKeep, std::min(removingContentLength,
                                                     aContentToKeep.Length())),
-        aContentToRemove, *removingContentIndex,
+        aContentToRemove, *keepingContentExIndex,
         JoinNodesDirection::LeftNodeIntoRightNode);
     NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored),
                          "RangeUpdater::SelAdjJoinNodes() failed, but ignored");
diff --git a/editor/libeditor/SelectionState.cpp b/editor/libeditor/SelectionState.cpp
index 42179428422c0..751cd21975381 100644
--- a/editor/libeditor/SelectionState.cpp
+++ b/editor/libeditor/SelectionState.cpp
@@ -327,7 +327,7 @@ nsresult RangeUpdater::SelAdjSplitNode(nsIContent& aOriginalContent,
 
 nsresult RangeUpdater::SelAdjJoinNodes(
     const EditorRawDOMPoint& aStartOfRightContent,
-    const nsIContent& aRemovedContent, uint32_t aOffsetOfRemovedContent,
+    const nsIContent& aRemovedContent, uint32_t aOffsetOfJoinedContent,
     JoinNodesDirection aJoinNodesDirection) {
   MOZ_ASSERT(aStartOfRightContent.IsSetAndValid());
 
@@ -343,14 +343,14 @@ nsresult RangeUpdater::SelAdjJoinNodes(
   auto AdjustDOMPoint = [&](nsCOMPtr<nsINode>& aContainer,
                             uint32_t& aOffset) -> void {
     if (aContainer == aStartOfRightContent.GetContainerParent()) {
-      // If the point is in common parent of joined content nodes and the
-      // point is after the removed point, decrease the offset.
-      if (aOffset > aOffsetOfRemovedContent) {
+      // If the point is in common parent of joined content nodes and it pointed
+      // after the right content node, decrease the offset.
+      if (aOffset > aOffsetOfJoinedContent) {
         aOffset--;
       }
-      // If it pointed the removed content node, move to start of right content
-      // which was moved from the removed content.
-      else if (aOffset == aOffsetOfRemovedContent) {
+      // If it pointed the right content node, adjust it to point ex-first
+      // content of the right node.
+      else if (aOffset == aOffsetOfJoinedContent) {
         aContainer = aStartOfRightContent.GetContainer();
         aOffset = aStartOfRightContent.Offset();
       }
diff --git a/editor/libeditor/SelectionState.h b/editor/libeditor/SelectionState.h
index 6d71d70d23b6b..b0ffdb42a10f6 100644
--- a/editor/libeditor/SelectionState.h
+++ b/editor/libeditor/SelectionState.h
@@ -231,12 +231,12 @@ class MOZ_STACK_CLASS RangeUpdater final {
    *                                in aRemovedContent.  And this points where
    *                                the joined position.
    * @param aRemovedContent         The removed content.
-   * @param aOffsetOfRemovedContent The offset which aRemovedContent was in
-   *                                its ex-parent.
+   * @param aOffsetOfJoinedContent  The offset which the container of
+   *                                aStartOfRightContent was in its parent.
    */
   nsresult SelAdjJoinNodes(const EditorRawDOMPoint& aStartOfRightContent,
                            const nsIContent& aRemovedContent,
-                           uint32_t aOffsetOfRemovedContent,
+                           uint32_t aOffsetOfJoinedContent,
                            JoinNodesDirection aJoinNodesDirection);
   void SelAdjInsertText(const dom::Text& aTextNode, uint32_t aOffset,
                         uint32_t aInsertedLength);
diff --git a/testing/web-platform/tests/editing/data/inserttext.js b/testing/web-platform/tests/editing/data/inserttext.js
index 59057d03c9136..ca90b9ae9cadc 100644
--- a/testing/web-platform/tests/editing/data/inserttext.js
+++ b/testing/web-platform/tests/editing/data/inserttext.js
@@ -1374,4 +1374,10 @@ var browserTests = [
     "<div style=\"white-space:pre-wrap\">a<br><span style=\"padding:1px\"></span><p>bc</p></div>",
     [true],
     {"inserttext":[false,false,"",false,false,""]}],
+// https://bugzilla.mozilla.org/show_bug.cgi?id=1785801
+["<div>abc{</div><div>}efg</div>",
+    [["inserttext", "d"]],
+    "<div>abcdefg</div>",
+    [true],
+    {"inserttext":[false,false,"",false,false,""]}],
 ]

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the tbb-commits mailing list