Bug 682564 - Prefer user set dictionary over other dictionaries when it matches spellcheck langcode; r=ehsan
☠☠ backed out by 873989b97eef ☠ ☠
authorarno renevier <arno@renevier.net>
Thu, 01 Sep 2011 22:14:02 +0100
changeset 76419 9ef862cbcc5e8968887f67250dfbd8aa301c9a78
parent 76418 d337401fc15086aaef8b1ef965ec9819ee317d0d
child 76420 e6fc4594c22eff5fb29eaf616129f81b1022bbb4
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewersehsan
bugs682564
milestone9.0a1
Bug 682564 - Prefer user set dictionary over other dictionaries when it matches spellcheck langcode; r=ehsan
editor/composer/src/nsEditorSpellCheck.cpp
--- a/editor/composer/src/nsEditorSpellCheck.cpp
+++ b/editor/composer/src/nsEditorSpellCheck.cpp
@@ -724,18 +724,19 @@ nsEditorSpellCheck::UpdateCurrentDiction
   }
 
   // Then, try to use language computed from element
   if (!mPreferredLang.IsEmpty()) {
     dictName.Assign(mPreferredLang);
   }
 
   // otherwise, get language from preferences
+  nsAutoString preferedDict(Preferences::GetLocalizedString("spellchecker.dictionary"));
   if (dictName.IsEmpty()) {
-    dictName.Assign(Preferences::GetLocalizedString("spellchecker.dictionary"));
+    dictName.Assign(preferedDict);
   }
 
   if (dictName.IsEmpty())
   {
     // Prefs didn't give us a dictionary name, so just get the current
     // locale and use that as the default dictionary name!
 
     nsCOMPtr<nsIXULChromeRegistry> packageRegistry =
@@ -750,37 +751,60 @@ nsEditorSpellCheck::UpdateCurrentDiction
   }
 
   SetCurrentDictionary(EmptyString());
 
   if (NS_SUCCEEDED(rv) && !dictName.IsEmpty()) {
     rv = SetCurrentDictionary(dictName);
     if (NS_FAILED(rv)) {
       // required dictionary was not available. Try to get a dictionary
-      // matching at least language part of dictName: If required dictionary is
-      // "aa-bb", we try "aa", then we try any available dictionary aa-XX
+      // matching at least language part of dictName: 
+
       nsAutoString langCode;
       PRInt32 dashIdx = dictName.FindChar('-');
       if (dashIdx != -1) {
         langCode.Assign(Substring(dictName, 0, dashIdx));
-        // try to use langCode
-        rv = SetCurrentDictionary(langCode);
       } else {
         langCode.Assign(dictName);
       }
+
+      nsDefaultStringComparator comparator;
+
+      // try dictionary.spellchecker preference if it starts with langCode (and
+      // if we haven't tried it already)
+      if (!preferedDict.IsEmpty() && !dictName.Equals(preferedDict) && 
+          nsStyleUtil::DashMatchCompare(preferedDict, langCode, comparator)) {
+        rv = SetCurrentDictionary(preferedDict);
+      }
+
+      // Otherwise, try langCode (if we haven't tried it already)
+      if (NS_FAILED(rv)) {
+        if (!dictName.Equals(langCode) && !preferedDict.Equals(langCode)) {
+          rv = SetCurrentDictionary(preferedDict);
+        }
+      }
+
+      // Otherwise, try any available dictionary aa-XX
       if (NS_FAILED(rv)) {
         // loop over avaible dictionaries; if we find one with required
         // language, use it
         nsTArray<nsString> dictList;
         rv = mSpellChecker->GetDictionaryList(&dictList);
         NS_ENSURE_SUCCESS(rv, rv);
-        nsDefaultStringComparator comparator;
         PRInt32 i, count = dictList.Length();
         for (i = 0; i < count; i++) {
           nsAutoString dictStr(dictList.ElementAt(i));
+
+          if (dictStr.Equals(dictName) ||
+              dictStr.Equals(preferedDict) ||
+              dictStr.Equals(langCode)) {
+            // We have already tried it
+            continue;
+          }
+
           if (nsStyleUtil::DashMatchCompare(dictStr, langCode, comparator) &&
               NS_SUCCEEDED(SetCurrentDictionary(dictStr))) {
               break;
           }
         }
       }
     }
   }