From d84fcf400fef8c7431d7745e7dc2fa1358910f1a Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Fri, 12 Nov 2021 22:19:51 +0000 Subject: [PATCH] Make `HTMLEditor::HandleInsertParagraphInParagraph()` call `WhiteSpaceVisibilityKeeper::PrepareToSplitBlockElement()` before splitting a text node It does the following things when caret is collapsed in a text node in a `

` or `

` element. 1. Split the text node containing caret to insert `
` element 2. Insert `
` element after it 3. Split ancestor elements which inclusive descendants of the `

` or `

` 4. Delete the `
` element if unnecessary from the left paragraph #3 and #4 are performed by `HTMLEditor::SplitParagraph()` and it calls `WhiteSpaceVisibilityKeeper::PrepareToSplitBlockElement()` correctly before splitting the block. However, in the case (caret is at middle of a text node), the text has already been split to 2 nodes because of #1. Therefore, it fails to handle to keep the white-space visibility. So that I believe that the root cause of this bug is, the method does much complicated things which are required, and doing the redundant things will eat memory space due to undo transactions. However, for now, I'd like to fix this with a simple patch which just call the preparation method before splitting the text node because I'd like to uplift this if it'd be approved (Note that this is not a recent regression, the root cause was created by bug 92686 which was fixed in 17 years ago: , but must be annoying bug for users who see this frequently). The new WPTs are pass in Chrome. Differential Revision: https://phabricator.services.mozilla.com/D130950 bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1740416 gecko-commit: 73567f6c2bcfa078836a36760498bb11747561dd gecko-reviewers: m_kato, smaug --- editing/data/insertparagraph.js | 105 ++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/editing/data/insertparagraph.js b/editing/data/insertparagraph.js index 21eb4579c7d99d..784678161243b4 100644 --- a/editing/data/insertparagraph.js +++ b/editing/data/insertparagraph.js @@ -1990,4 +1990,109 @@ var browserTests = [ "
ab
cd
/dd>
"], [true,true], {"insertparagraph":[false,false,"",false,false,""]}], + +// The first white-space of the second paragraph must be   for making it +// visible, but the other things do not matter for the following tests. +["
a[] b
", + [["defaultparagraphseparator","div"],["insertparagraph",""]], + "
a
 b
", + [true,true], + {"insertparagraph":[false,false,"",false,false,""]}], +// And if the first paragraph ends with white-space, the text node should be +// followed by
element. +["
a []b
", + [["defaultparagraphseparator","div"],["insertparagraph",""]], + ["
a
b
", + "
b
"], + [true,true], + {"insertparagraph":[false,false,"",false,false,""]}], +["
a [] b
", + [["defaultparagraphseparator","div"],["insertparagraph",""]], + ["
a
 b
", + "
 b
"], + [true,true], + {"insertparagraph":[false,false,"",false,false,""]}], +["
a [] b
", + [["defaultparagraphseparator","div"],["insertparagraph",""]], + ["
a
 b
", + "
 b
"], + [true,true], + {"insertparagraph":[false,false,"",false,false,""]}], +// These tests do not mind about the white-space sequence because it's not +// important here. That's tested by +// editing/other/white-spaces-after-execCommand-*.tentative.html +["
a []  b
", + [["defaultparagraphseparator","div"],["insertparagraph",""]], + ["
a
  b
", + "
  b
", + "
a
  b
", + "
  b
"], + [true,true], + {"insertparagraph":[false,false,"",false,false,""]}], +["
a []  b
", + [["defaultparagraphseparator","div"],["insertparagraph",""]], + ["
a
  b
", + "
  b
", + "
a
  b
", + "
  b
"], + [true,true], + {"insertparagraph":[false,false,"",false,false,""]}], +["
a []  b
", + [["defaultparagraphseparator","div"],["insertparagraph",""]], + ["
a
  b
", + "
  b
", + "
a
  b
", + "
  b
"], + [true,true], + {"insertparagraph":[false,false,"",false,false,""]}], +["
a  []  b
", + [["defaultparagraphseparator","div"],["insertparagraph",""]], + ["

  b
", + "
a  
  b
", + "
a  
  b
", + "

  b
", + "
a  
  b
", + "
a  
  b
"], + [true,true], + {"insertparagraph":[false,false,"",false,false,""]}], +["
a  []  b
", + [["defaultparagraphseparator","div"],["insertparagraph",""]], + ["

  b
", + "
a  
  b
", + "
a  
  b
", + "

  b
", + "
a  
  b
", + "
a  
  b
"], + [true,true], + {"insertparagraph":[false,false,"",false,false,""]}], +["
a  []  b
", + [["defaultparagraphseparator","div"],["insertparagraph",""]], + ["

  b
", + "
a  
  b
", + "
a  
  b
", + "

  b
", + "
a  
  b
", + "
a  
  b
"], + [true,true], + {"insertparagraph":[false,false,"",false,false,""]}], +["
a  []  b
", + [["defaultparagraphseparator","div"],["insertparagraph",""]], + ["

  b
", + "
a  
  b
", + "
a  
  b
", + "

  b
", + "
a  
  b
", + "
a  
  b
"], + [true,true], + {"insertparagraph":[false,false,"",false,false,""]}], +["
a  []  b
", + [["defaultparagraphseparator","div"],["insertparagraph",""]], + ["

  b
", + "
a  
  b
", + "
a  
  b
", + "

  b
", + "
a  
  b
", + "
a  
  b
"], + [true,true], + {"insertparagraph":[false,false,"",false,false,""]}], ]