Bug 1305355 part.3 IMEInputHandler shouldn't append any ranges when composition string is empty r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Mon, 26 Sep 2016 17:19:30 +0900
changeset 417814 a8c26b0bfb625e1ddf43e84dfde86d71002adbf5
parent 417813 f956bfaca1b7fe38a9453d40ea0bf3731651cd4f
child 532190 62b7d97abcb53d06a9f8eaf9e28ddc392130fbac
push id30511
push usermasayuki@d-toybox.com
push dateTue, 27 Sep 2016 05:42:37 +0000
reviewersm_kato
bugs1305355
milestone52.0a1
Bug 1305355 part.3 IMEInputHandler shouldn't append any ranges when composition string is empty r?m_kato IMEInputHandler shouldn't append any ranges to dispatch empty composition event since empty clause information may make TextComposition confused. Additionally, it doesn't need to append caret range because CompositionTransaction always sets caret at start of composition when the composition string is empty. MozReview-Commit-ID: FkLWePXZGJf
widget/cocoa/TextInputHandler.mm
--- a/widget/cocoa/TextInputHandler.mm
+++ b/widget/cocoa/TextInputHandler.mm
@@ -2803,24 +2803,31 @@ IMEInputHandler::GetRangeCount(NSAttribu
 }
 
 already_AddRefed<mozilla::TextRangeArray>
 IMEInputHandler::CreateTextRangeArray(NSAttributedString *aAttrString,
                                       NSRange& aSelectedRange)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
 
+  RefPtr<mozilla::TextRangeArray> textRangeArray =
+                                      new mozilla::TextRangeArray();
+
+  // Note that we shouldn't append ranges when composition string
+  // is empty because it may cause TextComposition confused.
+  if (![aAttrString length]) {
+    return textRangeArray.forget();
+  }
+
   // Convert the Cocoa range into the TextRange Array used in Gecko.
   // Iterate through the attributed string and map the underline attribute to
   // Gecko IME textrange attributes.  We may need to change the code here if
   // we change the implementation of validAttributesForMarkedText.
   NSRange limitRange = NSMakeRange(0, [aAttrString length]);
   uint32_t rangeCount = GetRangeCount(aAttrString);
-  RefPtr<mozilla::TextRangeArray> textRangeArray =
-                                      new mozilla::TextRangeArray();
   for (uint32_t i = 0; i < rangeCount && limitRange.length > 0; i++) {
     NSRange effectiveRange;
     id attributeValue = [aAttrString attribute:NSUnderlineStyleAttributeName
                                        atIndex:limitRange.location
                          longestEffectiveRange:&effectiveRange
                                        inRange:limitRange];
 
     TextRange range;