Skip to content

Commit d84fcf4

Browse files
masayuki-nakanomoz-wptsync-bot
authored andcommitted
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 `<p>` or `<div>` element. 1. Split the text node containing caret to insert `<br>` element 2. Insert `<br>` element after it 3. Split ancestor elements which inclusive descendants of the `<p>` or `<div>` 4. Delete the `<br>` 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: <https://searchfox.org/mozilla-central/commit/2e66280faef73e9be218e00758d4eb738395ac83>, 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
1 parent dc91bc4 commit d84fcf4

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

editing/data/insertparagraph.js

+105
Original file line numberDiff line numberDiff line change
@@ -1990,4 +1990,109 @@ var browserTests = [
19901990
"<dl contenteditable=\"false\"><dd contenteditable=\"\"><div>ab</div><div>cd<br></div>/dd></dl>"],
19911991
[true,true],
19921992
{"insertparagraph":[false,false,"",false,false,""]}],
1993+
1994+
// The first white-space of the second paragraph must be &nbsp; for making it
1995+
// visible, but the other things do not matter for the following tests.
1996+
["<div>a[] b</div>",
1997+
[["defaultparagraphseparator","div"],["insertparagraph",""]],
1998+
"<div>a</div><div>&nbsp;b</div>",
1999+
[true,true],
2000+
{"insertparagraph":[false,false,"",false,false,""]}],
2001+
// And if the first paragraph ends with white-space, the text node should be
2002+
// followed by <br> element.
2003+
["<div>a []b</div>",
2004+
[["defaultparagraphseparator","div"],["insertparagraph",""]],
2005+
["<div>a <br></div><div>b</div>",
2006+
"<div>a&nbsp;</div><div>b</div>"],
2007+
[true,true],
2008+
{"insertparagraph":[false,false,"",false,false,""]}],
2009+
["<div>a&nbsp;[] b</div>",
2010+
[["defaultparagraphseparator","div"],["insertparagraph",""]],
2011+
["<div>a <br></div><div>&nbsp;b</div>",
2012+
"<div>a&nbsp;</div><div>&nbsp;b</div>"],
2013+
[true,true],
2014+
{"insertparagraph":[false,false,"",false,false,""]}],
2015+
["<div>a []&nbsp;b</div>",
2016+
[["defaultparagraphseparator","div"],["insertparagraph",""]],
2017+
["<div>a <br></div><div>&nbsp;b</div>",
2018+
"<div>a&nbsp;</div><div>&nbsp;b</div>"],
2019+
[true,true],
2020+
{"insertparagraph":[false,false,"",false,false,""]}],
2021+
// These tests do not mind about the white-space sequence because it's not
2022+
// important here. That's tested by
2023+
// editing/other/white-spaces-after-execCommand-*.tentative.html
2024+
["<div>a&nbsp;[]&nbsp; b</div>",
2025+
[["defaultparagraphseparator","div"],["insertparagraph",""]],
2026+
["<div>a <br></div><div>&nbsp; b</div>",
2027+
"<div>a&nbsp;</div><div>&nbsp; b</div>",
2028+
"<div>a <br></div><div>&nbsp;&nbsp;b</div>",
2029+
"<div>a&nbsp;</div><div>&nbsp;&nbsp;b</div>"],
2030+
[true,true],
2031+
{"insertparagraph":[false,false,"",false,false,""]}],
2032+
["<div>a&nbsp;[] &nbsp;b</div>",
2033+
[["defaultparagraphseparator","div"],["insertparagraph",""]],
2034+
["<div>a <br></div><div>&nbsp; b</div>",
2035+
"<div>a&nbsp;</div><div>&nbsp; b</div>",
2036+
"<div>a <br></div><div>&nbsp;&nbsp;b</div>",
2037+
"<div>a&nbsp;</div><div>&nbsp;&nbsp;b</div>"],
2038+
[true,true],
2039+
{"insertparagraph":[false,false,"",false,false,""]}],
2040+
["<div>a []&nbsp; b</div>",
2041+
[["defaultparagraphseparator","div"],["insertparagraph",""]],
2042+
["<div>a <br></div><div>&nbsp; b</div>",
2043+
"<div>a&nbsp;</div><div>&nbsp; b</div>",
2044+
"<div>a <br></div><div>&nbsp;&nbsp;b</div>",
2045+
"<div>a&nbsp;</div><div>&nbsp;&nbsp;b</div>"],
2046+
[true,true],
2047+
{"insertparagraph":[false,false,"",false,false,""]}],
2048+
["<div>a&nbsp;&nbsp;[]&nbsp; b</div>",
2049+
[["defaultparagraphseparator","div"],["insertparagraph",""]],
2050+
["<div>a&nbsp; <br></div><div>&nbsp; b</div>",
2051+
"<div>a&nbsp;&nbsp;</div><div>&nbsp; b</div>",
2052+
"<div>a &nbsp;</div><div>&nbsp; b</div>",
2053+
"<div>a&nbsp; <br></div><div>&nbsp;&nbsp;b</div>",
2054+
"<div>a&nbsp;&nbsp;</div><div>&nbsp;&nbsp;b</div>",
2055+
"<div>a &nbsp;</div><div>&nbsp;&nbsp;b</div>"],
2056+
[true,true],
2057+
{"insertparagraph":[false,false,"",false,false,""]}],
2058+
["<div>a&nbsp; []&nbsp; b</div>",
2059+
[["defaultparagraphseparator","div"],["insertparagraph",""]],
2060+
["<div>a&nbsp; <br></div><div>&nbsp; b</div>",
2061+
"<div>a&nbsp;&nbsp;</div><div>&nbsp; b</div>",
2062+
"<div>a &nbsp;</div><div>&nbsp; b</div>",
2063+
"<div>a&nbsp; <br></div><div>&nbsp;&nbsp;b</div>",
2064+
"<div>a&nbsp;&nbsp;</div><div>&nbsp;&nbsp;b</div>",
2065+
"<div>a &nbsp;</div><div>&nbsp;&nbsp;b</div>"],
2066+
[true,true],
2067+
{"insertparagraph":[false,false,"",false,false,""]}],
2068+
["<div>a &nbsp;[]&nbsp; b</div>",
2069+
[["defaultparagraphseparator","div"],["insertparagraph",""]],
2070+
["<div>a&nbsp; <br></div><div>&nbsp; b</div>",
2071+
"<div>a&nbsp;&nbsp;</div><div>&nbsp; b</div>",
2072+
"<div>a &nbsp;</div><div>&nbsp; b</div>",
2073+
"<div>a&nbsp; <br></div><div>&nbsp;&nbsp;b</div>",
2074+
"<div>a&nbsp;&nbsp;</div><div>&nbsp;&nbsp;b</div>",
2075+
"<div>a &nbsp;</div><div>&nbsp;&nbsp;b</div>"],
2076+
[true,true],
2077+
{"insertparagraph":[false,false,"",false,false,""]}],
2078+
["<div>a&nbsp;&nbsp;[] &nbsp;b</div>",
2079+
[["defaultparagraphseparator","div"],["insertparagraph",""]],
2080+
["<div>a&nbsp; <br></div><div>&nbsp; b</div>",
2081+
"<div>a&nbsp;&nbsp;</div><div>&nbsp; b</div>",
2082+
"<div>a &nbsp;</div><div>&nbsp; b</div>",
2083+
"<div>a&nbsp; <br></div><div>&nbsp;&nbsp;b</div>",
2084+
"<div>a&nbsp;&nbsp;</div><div>&nbsp;&nbsp;b</div>",
2085+
"<div>a &nbsp;</div><div>&nbsp;&nbsp;b</div>"],
2086+
[true,true],
2087+
{"insertparagraph":[false,false,"",false,false,""]}],
2088+
["<div>a &nbsp;[] &nbsp;b</div>",
2089+
[["defaultparagraphseparator","div"],["insertparagraph",""]],
2090+
["<div>a&nbsp; <br></div><div>&nbsp; b</div>",
2091+
"<div>a&nbsp;&nbsp;</div><div>&nbsp; b</div>",
2092+
"<div>a &nbsp;</div><div>&nbsp; b</div>",
2093+
"<div>a&nbsp; <br></div><div>&nbsp;&nbsp;b</div>",
2094+
"<div>a&nbsp;&nbsp;</div><div>&nbsp;&nbsp;b</div>",
2095+
"<div>a &nbsp;</div><div>&nbsp;&nbsp;b</div>"],
2096+
[true,true],
2097+
{"insertparagraph":[false,false,"",false,false,""]}],
19932098
]

0 commit comments

Comments
 (0)