Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1097550 - "System dictionaries with underscore separator are igno…
Browse files Browse the repository at this point in the history
…red when trying to find dictionary". r=ehsan
  • Loading branch information
xhorak committed Dec 2, 2014
1 parent 986cd10 commit 26f4896
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions editor/composer/nsEditorSpellCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,23 @@ GetLoadContext(nsIEditor* aEditor)
return loadContext.forget();
}

/**
* 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.
Expand Down Expand Up @@ -603,8 +620,8 @@ nsEditorSpellCheck::SetCurrentDictionary(const nsAString& aDictionary)
} 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);
Expand Down Expand Up @@ -750,12 +767,6 @@ nsEditorSpellCheck::DictionaryFetched(DictionaryFetcher* aFetcher)

// 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);
}
Expand Down Expand Up @@ -794,8 +805,8 @@ nsEditorSpellCheck::DictionaryFetched(DictionaryFetcher* aFetcher)

// 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);
}

Expand Down Expand Up @@ -823,8 +834,7 @@ nsEditorSpellCheck::DictionaryFetched(DictionaryFetcher* aFetcher)
// We have already tried it
continue;
}

if (nsStyleUtil::DashMatchCompare(dictStr, langCode, comparator) &&
if (nsStyleUtil::DashMatchCompare(GetDictNameWithDash(dictStr), langCode, comparator) &&
NS_SUCCEEDED(SetCurrentDictionary(dictStr))) {
break;
}
Expand Down

0 comments on commit 26f4896

Please sign in to comment.