mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 11:25:00 +00:00
Bug 338427 followup - Do not override manually set dictionary; r=ehsan
This commit is contained in:
parent
d6491157c3
commit
c4a382824d
@ -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<nsString> dictList;
|
||||
|
@ -78,6 +78,13 @@ protected:
|
||||
nsresult DeleteSuggestedWordList();
|
||||
|
||||
nsCOMPtr<nsITextServicesFilter> mTxtSrvFilter;
|
||||
|
||||
PRPackedBool mUpdateDictionaryRunning;
|
||||
PRPackedBool mDictWasSetManually;
|
||||
|
||||
public:
|
||||
void BeginUpdateDictionary() { mUpdateDictionaryRunning = PR_TRUE ;}
|
||||
void EndUpdateDictionary() { mUpdateDictionaryRunning = PR_FALSE ;}
|
||||
};
|
||||
|
||||
#endif // nsEditorSpellCheck_h___
|
||||
|
@ -53,6 +53,7 @@ _TEST_FILES = \
|
||||
|
||||
_CHROME_TEST_FILES = \
|
||||
test_bug434998.xul \
|
||||
test_bug338427.html \
|
||||
$(NULL)
|
||||
|
||||
libs:: $(_TEST_FILES)
|
||||
|
54
editor/composer/test/test_bug338427.html
Normal file
54
editor/composer/test/test_bug338427.html
Normal file
@ -0,0 +1,54 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=338427
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug 338427</title>
|
||||
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=338427">Mozilla Bug 338427</a>
|
||||
<p id="display"></p>
|
||||
<div id="content">
|
||||
<textarea id="editor" lang="testing-XX"></textarea>
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script class="testbody" type="text/javascript">
|
||||
|
||||
/** Test for Bug 338427 **/
|
||||
function init() {
|
||||
var textarea = document.getElementById("editor");
|
||||
var editor = textarea.QueryInterface(Components.interfaces.nsIDOMNSEditableElement).editor;
|
||||
var spellchecker = editor.getInlineSpellChecker(true);
|
||||
spellchecker.enableRealTimeSpell = true;
|
||||
|
||||
var list = {}, count = {};
|
||||
spellchecker.spellChecker.GetDictionaryList(list, count);
|
||||
if (count.value === 0) {
|
||||
return; // no dictionary, no test possible
|
||||
}
|
||||
var lang = list.value[0];
|
||||
spellchecker.spellChecker.SetCurrentDictionary(lang);
|
||||
|
||||
textarea.addEventListener("focus", function() {
|
||||
var dictionary = "";
|
||||
try {
|
||||
dictionary = spellchecker.spellChecker.GetCurrentDictionary();
|
||||
} catch(e) {}
|
||||
is(dictionary, lang, "Unexpected spell check dictionary");
|
||||
SimpleTest.finish();
|
||||
}, false);
|
||||
textarea.focus();
|
||||
}
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
addLoadEvent(init);
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
Reference in New Issue
Block a user