Bug 1394758 - Part 2. WSRunObject::InsertBreak should convert space to NBSP when current position is first text run object. r=masayuki
After applying part 1 fix, it doesn't pass test_bug430392.html like the following..
1. content is <span contenteditable=false>A</span>[caret] ;
2. [VK_RETURN]
3. content is <span contenteditable=false>A</span><br>; <- whitespace is removed
Since we started to treat readonly text nodes as WSType::special with previous patch, WSRunObject::InsertBreak doesn't convert space (after caret) to NBSP because WSRunObject::InsertBreak does it only when inserted position isn't first text run object.
So even if this is first text run object, space after caret should be converted to NBSP.
MozReview-Commit-ID: Hj0i3wm45c3
--- a/editor/libeditor/WSRunObject.cpp
+++ b/editor/libeditor/WSRunObject.cpp
@@ -197,17 +197,18 @@ WSRunObject::InsertBreak(nsCOMPtr<nsINod
afterRun->mEndNode, afterRun->mEndOffset);
NS_ENSURE_SUCCESS(rv, nullptr);
} else if (afterRun->mType == WSType::normalWS) {
// Need to determine if break at front of non-nbsp run. If so, convert
// run to nbsp.
WSPoint thePoint = GetCharAfter(*aInOutParent, *aInOutOffset);
if (thePoint.mTextNode && nsCRT::IsAsciiSpace(thePoint.mChar)) {
WSPoint prevPoint = GetCharBefore(thePoint);
- if (prevPoint.mTextNode && !nsCRT::IsAsciiSpace(prevPoint.mChar)) {
+ if (!prevPoint.mTextNode ||
+ (prevPoint.mTextNode && !nsCRT::IsAsciiSpace(prevPoint.mChar))) {
// We are at start of non-nbsps. Convert to a single nbsp.
nsresult rv = ConvertToNBSP(thePoint);
NS_ENSURE_SUCCESS(rv, nullptr);
}
}
}
// Handle any changes needed to ws run before inserted br