diff --git a/editor/composer/src/nsEditorSpellCheck.cpp b/editor/composer/src/nsEditorSpellCheck.cpp index 9310f4b99132..be27a208096d 100644 --- a/editor/composer/src/nsEditorSpellCheck.cpp +++ b/editor/composer/src/nsEditorSpellCheck.cpp @@ -64,6 +64,22 @@ using namespace mozilla; +class UpdateDictionnaryHolder { + private: + nsEditorSpellCheck* mSpellCheck; + public: + UpdateDictionnaryHolder(nsEditorSpellCheck* esc): mSpellCheck(esc) { + if (mSpellCheck) { + mSpellCheck->BeginUpdateDictionary(); + } + } + ~UpdateDictionnaryHolder() { + if (mSpellCheck) { + mSpellCheck->EndUpdateDictionary(); + } + } +}; + NS_IMPL_CYCLE_COLLECTING_ADDREF(nsEditorSpellCheck) NS_IMPL_CYCLE_COLLECTING_RELEASE(nsEditorSpellCheck) @@ -80,6 +96,8 @@ NS_IMPL_CYCLE_COLLECTION_2(nsEditorSpellCheck, nsEditorSpellCheck::nsEditorSpellCheck() : mSuggestedWordIndex(0) , mDictionaryIndex(0) + , mUpdateDictionaryRunning(PR_FALSE) + , mDictWasSetManually(PR_FALSE) { } @@ -384,6 +402,9 @@ nsEditorSpellCheck::SetCurrentDictionary(const PRUnichar *aDictionary) NS_ENSURE_TRUE(aDictionary, NS_ERROR_NULL_POINTER); + if (!mUpdateDictionaryRunning) { + mDictWasSetManually = PR_TRUE; + } return mSpellChecker->SetCurrentDictionary(nsDependentString(aDictionary)); } @@ -400,10 +421,13 @@ nsEditorSpellCheck::UninitSpellChecker() return NS_OK; } -// Save the last used dictionary to the user's preferences. +// Save the last set dictionary to the user's preferences. NS_IMETHODIMP nsEditorSpellCheck::SaveDefaultDictionary() { + if (!mDictWasSetManually) { + return NS_OK; + } PRUnichar *dictName = nsnull; nsresult rv = GetCurrentDictionary(&dictName); @@ -438,8 +462,14 @@ nsEditorSpellCheck::DeleteSuggestedWordList() NS_IMETHODIMP nsEditorSpellCheck::UpdateCurrentDictionary(nsIEditor* aEditor) { + if (mDictWasSetManually) { // user has set dictionary manually; we better not change it. + return NS_OK; + } + nsresult rv; + UpdateDictionnaryHolder holder(this); + // Tell the spellchecker what dictionary to use: nsAutoString dictName; @@ -532,9 +562,9 @@ nsEditorSpellCheck::UpdateCurrentDictionary(nsIEditor* aEditor) // lang attribute, we try to get a dictionary. First try, en-US. If it does // not work, pick the first one. if (editorLang.IsEmpty()) { - nsAutoString currentDictonary; - rv = mSpellChecker->GetCurrentDictionary(currentDictonary); - if (NS_FAILED(rv) || currentDictonary.IsEmpty()) { + nsAutoString currentDictionary; + rv = mSpellChecker->GetCurrentDictionary(currentDictionary); + if (NS_FAILED(rv) || currentDictionary.IsEmpty()) { rv = SetCurrentDictionary(NS_LITERAL_STRING("en-US").get()); if (NS_FAILED(rv)) { nsTArray dictList; diff --git a/editor/composer/src/nsEditorSpellCheck.h b/editor/composer/src/nsEditorSpellCheck.h index c8cdd6866c5d..094ae5467b8a 100644 --- a/editor/composer/src/nsEditorSpellCheck.h +++ b/editor/composer/src/nsEditorSpellCheck.h @@ -78,6 +78,13 @@ protected: nsresult DeleteSuggestedWordList(); nsCOMPtr mTxtSrvFilter; + + PRPackedBool mUpdateDictionaryRunning; + PRPackedBool mDictWasSetManually; + +public: + void BeginUpdateDictionary() { mUpdateDictionaryRunning = PR_TRUE ;} + void EndUpdateDictionary() { mUpdateDictionaryRunning = PR_FALSE ;} }; #endif // nsEditorSpellCheck_h___ diff --git a/editor/composer/test/Makefile.in b/editor/composer/test/Makefile.in index 7baa1ee0aec2..d7dffb7d5c4b 100644 --- a/editor/composer/test/Makefile.in +++ b/editor/composer/test/Makefile.in @@ -53,6 +53,7 @@ _TEST_FILES = \ _CHROME_TEST_FILES = \ test_bug434998.xul \ + test_bug338427.html \ $(NULL) libs:: $(_TEST_FILES) diff --git a/editor/composer/test/test_bug338427.html b/editor/composer/test/test_bug338427.html new file mode 100644 index 000000000000..bce1218b3df5 --- /dev/null +++ b/editor/composer/test/test_bug338427.html @@ -0,0 +1,54 @@ + + + + + Test for Bug 338427 + + + + +Mozilla Bug 338427 +

+
+ + +
+
+
+
+ + +