Bug 1394758 - Part 2. WSRunObject::InsertBreak should convert space to NBSP when current position is first text run object. r=masayuki
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Mon, 04 Sep 2017 15:01:16 +0900
changeset 429513 c65dfa68df8da69f30e8f58715383de179a51397
parent 429512 adcfea5cd531baec52c58f8659c35fe02ac2a56c
child 429514 86465f8cfaf3404b7ed15f7a2f74b9e2e54f8121
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmasayuki
bugs1394758, 430392
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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