summaryrefslogtreecommitdiff
path: root/mozilla-1097550-dict-fix.patch
blob: 9237247624f147afdb3b27d70cbb9ec55d9ffe08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
diff -up mozilla-release/editor/composer/nsEditorSpellCheck.cpp.1097550-dict-fix mozilla-release/editor/composer/nsEditorSpellCheck.cpp
--- mozilla-release/editor/composer/nsEditorSpellCheck.cpp.1097550-dict-fix	2014-11-26 03:17:14.000000000 +0100
+++ mozilla-release/editor/composer/nsEditorSpellCheck.cpp	2014-12-04 16:45:07.192923283 +0100
@@ -103,6 +103,23 @@ GetLoadContext(nsIEditor* aEditor)
 }
 
 /**
+ * Helper function for converting underscore to dash in dictionary name,
+ * ie. en_CA to en-CA. This is required for some Linux distributions which
+ * use underscore as separator in system-wide installed dictionaries.
+ * We use it for nsStyleUtil::DashMatchCompare.
+ */
+static nsString
+GetDictNameWithDash(const nsAString& aDictName)
+{
+  nsString dictNameWithDash(aDictName);
+  int32_t underScore = dictNameWithDash.FindChar('_');
+  if (underScore != -1) {
+    dictNameWithDash.Replace(underScore, 1, '-');
+  }
+  return dictNameWithDash;
+}
+
+/**
  * Fetches the dictionary stored in content prefs and maintains state during the
  * fetch, which is asynchronous.
  */
@@ -606,8 +623,8 @@ nsEditorSpellCheck::SetCurrentDictionary
     } else {
       langCode.Assign(aDictionary);
     }
-
-    if (mPreferredLang.IsEmpty() || !nsStyleUtil::DashMatchCompare(mPreferredLang, langCode, comparator)) {
+    if (mPreferredLang.IsEmpty() ||
+        !nsStyleUtil::DashMatchCompare(GetDictNameWithDash(mPreferredLang), langCode, comparator)) {
       // When user sets dictionary manually, we store this value associated
       // with editor url.
       StoreCurrentDictionary(mEditor, aDictionary);
@@ -763,12 +780,6 @@ nsEditorSpellCheck::DictionaryFetched(Di
 
   // otherwise, get language from preferences
   nsAutoString preferedDict(Preferences::GetLocalizedString("spellchecker.dictionary"));
-  // Replace '_' with '-' in case the user has an underscore stored in their
-  // pref, see bug 992118 for how this could have happened.
-  int32_t underScore = preferedDict.FindChar('_');
-  if (underScore != -1) {
-    preferedDict.Replace(underScore, 1, '-');
-  }
   if (dictName.IsEmpty()) {
     dictName.Assign(preferedDict);
   }
@@ -807,8 +818,8 @@ nsEditorSpellCheck::DictionaryFetched(Di
 
       // 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)) {
+      if (!preferedDict.IsEmpty() && !dictName.Equals(preferedDict) &&
+          nsStyleUtil::DashMatchCompare(GetDictNameWithDash(preferedDict), langCode, comparator)) {
         rv = SetCurrentDictionary(preferedDict);
       }
 
@@ -836,8 +847,7 @@ nsEditorSpellCheck::DictionaryFetched(Di
             // We have already tried it
             continue;
           }
-
-          if (nsStyleUtil::DashMatchCompare(dictStr, langCode, comparator) &&
+          if (nsStyleUtil::DashMatchCompare(GetDictNameWithDash(dictStr), langCode, comparator) &&
               NS_SUCCEEDED(SetCurrentDictionary(dictStr))) {
               break;
           }
bgstack15