Bug 1394758 - Part 2. WSRunObject::InsertBreak should convert space to NBSP when current position is first text run object. r=masayuki draft
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Mon, 04 Sep 2017 15:01:16 +0900
changeset 662205 2d0ae7c47c6187e56d6c29e8eb48974f7ab7ff72
parent 662204 e5fff30a2710c2021d59ce88bf2698ce4ebe2dfc
child 730781 de96b53a446a4dcefdb740d9eb3460fc8bee0a20
push id78991
push userbmo:m_kato@ga2.so-net.ne.jp
push dateMon, 11 Sep 2017 07:01:16 +0000
reviewersmasayuki
bugs1394758, 430392
milestone57.0a1
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
editor/libeditor/WSRunObject.cpp
--- 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