Commit 3222cb94 authored by Masayuki Nakano's avatar Masayuki Nakano
Browse files

Bug 1661893 - Make `WhiteSpaceVisibilityKeeper::ReplaceText()` refer replacing...

Bug 1661893 - Make `WhiteSpaceVisibilityKeeper::ReplaceText()` refer replacing range end information to consider whether the last ASCII white-space of inserting string should be replaced with an NBSP or not. r=m_kato, a=RyanVM

This is simple mistake of the patch:
https://phabricator.services.mozilla.com/D82286

The method refers start of replacing range to consider whether replace or
keep last ASCII white-space of inserting string, but it should refer the
end of the replacing range, of course.

Differential Revision: https://phabricator.services.mozilla.com/D89124
parent 6eae8df6
......@@ -647,14 +647,14 @@ nsresult WhiteSpaceVisibilityKeeper::ReplaceText(
RefPtr<Element> editingHost = aHTMLEditor.GetActiveEditingHost();
TextFragmentData textFragmentDataAtStart(aRangeToBeReplaced.StartRef(),
editingHost);
const bool insertionPointEqualsOrIsBeforeStartOfText =
const bool isInsertionPointEqualsOrIsBeforeStartOfText =
aRangeToBeReplaced.StartRef().EqualsOrIsBefore(
textFragmentDataAtStart.StartRef());
TextFragmentData textFragmentDataAtEnd =
aRangeToBeReplaced.Collapsed()
? textFragmentDataAtStart
: TextFragmentData(aRangeToBeReplaced.EndRef(), editingHost);
const bool insertionPointAfterEndOfText =
const bool isInsertionPointEqualsOrAfterEndOfText =
textFragmentDataAtEnd.EndRef().EqualsOrIsBefore(
aRangeToBeReplaced.EndRef());
......@@ -813,7 +813,7 @@ nsresult WhiteSpaceVisibilityKeeper::ReplaceText(
// immediately after a hard line break, the first ASCII white-space should
// be replaced with an NBSP for making it visible.
else if (textFragmentDataAtStart.StartsFromHardLineBreak() &&
insertionPointEqualsOrIsBeforeStartOfText) {
isInsertionPointEqualsOrIsBeforeStartOfText) {
theString.SetCharAt(kNBSP, 0);
}
}
......@@ -830,12 +830,12 @@ nsresult WhiteSpaceVisibilityKeeper::ReplaceText(
// If inserting around visible white-spaces, check whether the inclusive
// next character of end of replaced range is an NBSP or an ASCII
// white-space.
if (pointPositionWithVisibleWhiteSpacesAtStart ==
if (pointPositionWithVisibleWhiteSpacesAtEnd ==
PointPosition::StartOfFragment ||
pointPositionWithVisibleWhiteSpacesAtStart ==
pointPositionWithVisibleWhiteSpacesAtEnd ==
PointPosition::MiddleOfFragment) {
EditorDOMPointInText atNextChar =
textFragmentDataAtStart.GetInclusiveNextEditableCharPoint(
textFragmentDataAtEnd.GetInclusiveNextEditableCharPoint(
pointToInsert);
if (atNextChar.IsSet() && !atNextChar.IsEndOfContainer() &&
atNextChar.IsCharASCIISpace()) {
......@@ -846,7 +846,7 @@ nsresult WhiteSpaceVisibilityKeeper::ReplaceText(
// immediately before block boundary, the last ASCII white-space should
// be replaced with an NBSP for making it visible.
else if (textFragmentDataAtEnd.EndsByBlockBoundary() &&
insertionPointAfterEndOfText) {
isInsertionPointEqualsOrAfterEndOfText) {
theString.SetCharAt(kNBSP, lastCharIndex);
}
}
......
......@@ -5357,7 +5357,7 @@ async function runBug1584901Test()
"runBug1584901Test: space must not be removed by composition change");
}
function runBug1636747Test()
function runCommitCompositionWithSpaceKey()
{
contenteditable.focus();
contenteditable.innerHTML = "";
......@@ -5372,8 +5372,8 @@ function runBug1636747Test()
synthesizeComposition({type: "compositioncommit", data: "a"});
synthesizeKey(" ");
is(contenteditable.textContent, "a ",
"runBug1636747Test: last single space should be kept");
is(contenteditable.innerHTML, "a <br>",
"runCommitCompositionWithSpaceKey: last single space should be kept");
synthesizeCompositionChange({
composition: {string: "b", clauses: [{length: 1, attr: COMPOSITION_ATTR_RAW_CLAUSE}]},
......@@ -5381,8 +5381,8 @@ function runBug1636747Test()
synthesizeComposition({type: "compositioncommit", data: "b"});
synthesizeKey(" ");
is(contenteditable.textContent, "a b ",
"runBug1636747Test: inserting composition shouldn't remove last single space.");
is(contenteditable.innerHTML, "a b <br>",
"runCommitCompositionWithSpaceKey: inserting composition shouldn't remove last single space.");
synthesizeCompositionChange({
composition: {string: "c", clauses: [{length: 1, attr: COMPOSITION_ATTR_RAW_CLAUSE}]},
......@@ -5390,8 +5390,21 @@ function runBug1636747Test()
synthesizeComposition({type: "compositioncommit", data: "c"});
synthesizeKey(" ");
is(contenteditable.textContent, "a b c ",
"runBug1636747Test: inserting composition shouldn't remove last single space.");
is(contenteditable.innerHTML, "a b c <br>",
"runCommitCompositionWithSpaceKey: inserting composition shouldn't remove last single space.");
contenteditable.innerHTML = "a";
windowOfContenteditable.getSelection().collapse(contenteditable.firstChild, contenteditable.firstChild.length);
is(contenteditable.innerHTML, "a",
"runCommitCompositionWithSpaceKey: contenteditable should be initialized with text ending with a space and without following <br> element");
synthesizeCompositionChange({
composition: {string: "b", clauses: [{length: 1, attr: COMPOSITION_ATTR_RAW_CLAUSE}]},
});
synthesizeComposition({type: "compositioncommit", data: "b ", key: { key: " ", code: "Space" }});
is(contenteditable.innerHTML, "ab <br>",
"runCommitCompositionWithSpaceKey: contenteditable should end with a padding <br> element after inserting commit string ending with a space");
}
function runCSSTransformTest()
......@@ -9558,7 +9571,7 @@ async function runTest()
runBug1375825Test();
runBug1530649Test();
runBug1571375Test();
runBug1636747Test();
runCommitCompositionWithSpaceKey();
runForceCommitTest();
runNestedSettingValue();
runBug811755Test();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment