Bug 1277658 - Always use document language to drive spelling button. Reworked ChangeLanguage(). r=aceman a=jorgk BETA_BASE_20160606
authorJorg K
Sat, 04 Jun 2016 16:45:14 +0200
changeset 63024 80242da9baf35c56dc97f69c11c0d0bce64f6397
parent 63023 c5eb848ac878e7a7665087bdcb23e722a1386c12
child 63025 17f511767d3203b1d7edf9df86b2a2f30272e465
push id6375
push usergeoff@darktrojan.net
push dateSun, 17 Jun 2018 08:49:04 +0000
treeherdertry-comm-central@b9dbeef12524 [default view] [failures only]
reviewersaceman, jorgk
bugs1277658
Bug 1277658 - Always use document language to drive spelling button. Reworked ChangeLanguage(). r=aceman a=jorgk
mail/components/compose/content/MsgComposeCommands.js
--- a/mail/components/compose/content/MsgComposeCommands.js
+++ b/mail/components/compose/content/MsgComposeCommands.js
@@ -3272,24 +3272,20 @@ function InitLanguageMenu()
     item.setAttribute('type', 'radio');
     languageMenuList.appendChild(item);
   }
 }
 
 function OnShowDictionaryMenu(aTarget)
 {
   InitLanguageMenu();
-  let spellChecker = gSpellChecker.mInlineSpellChecker.spellChecker;
-  let curLang = spellChecker.GetCurrentDictionary();
-  if (!curLang || curLang != document.documentElement.getAttribute("lang")) {
-    // Looks like the active dictionary got removed, or something is
-    // inconsistent. In this case do not check anything, so the user can select
-    // another dictionary.
+  let curLang = document.documentElement.getAttribute("lang");
+  if (!curLang)
     return;
-  }
+
   let language = aTarget.querySelector('[value="' + curLang + '"]');
   if (language)
     language.setAttribute("checked", true);
 }
 
 function updateLanguageInStatusBar()
 {
   InitLanguageMenu();
@@ -3314,40 +3310,46 @@ function updateLanguageInStatusBar()
     if (item.getAttribute("value") == language) {
       statusLanguageText.label = item.getAttribute("label");
       break;
     }
     item = item.nextSibling;
   }
 }
 
+/**
+ * Change the language of the composition and if we are using inline
+ * spell check, recheck the message with the new dictionary.
+ *
+ * @param event  Event of selecting an item in the spelling button menulist popup.
+ */
 function ChangeLanguage(event)
 {
-  // We need to change the dictionary language and if we are using inline spell check,
-  // recheck the message
-
-  var spellChecker = gSpellChecker.mInlineSpellChecker.spellChecker;
-  if (spellChecker.GetCurrentDictionary() != event.target.value)
-  {
-    spellChecker.SetCurrentDictionary(event.target.value);
-
+  let newLang = event.target.value;
+
+  if (document.documentElement.getAttribute("lang") != newLang) {
     // Update the document language as well (needed to synchronise
     // the subject).
-    document.documentElement.setAttribute("lang", event.target.value);
-
-    // now check the document over again with the new dictionary
-    if (gSpellChecker.enabled) {
-      gSpellChecker.mInlineSpellChecker.spellCheckRange(null);
-
-      // Also force a recheck of the subject. If for some reason the spell
-      // checker isn't ready yet, don't auto-create it, hence pass 'false'.
-      var inlineSpellChecker =
-        GetMsgSubjectElement().editor.getInlineSpellChecker(false);
-      if (inlineSpellChecker) {
-        inlineSpellChecker.spellCheckRange(null);
+    document.documentElement.setAttribute("lang", newLang);
+
+    let spellChecker = gSpellChecker.mInlineSpellChecker.spellChecker;
+    if (spellChecker) {
+      spellChecker.SetCurrentDictionary(newLang);
+
+      // now check the document over again with the new dictionary
+      if (gSpellChecker.enabled) {
+        gSpellChecker.mInlineSpellChecker.spellCheckRange(null);
+
+        // Also force a recheck of the subject. If for some reason the spell
+        // checker isn't ready yet, don't auto-create it, hence pass 'false'.
+        let inlineSpellChecker =
+          GetMsgSubjectElement().editor.getInlineSpellChecker(false);
+        if (inlineSpellChecker) {
+          inlineSpellChecker.spellCheckRange(null);
+        }
       }
     }
   }
   event.stopPropagation();
 }
 
 function ToggleReturnReceipt(target)
 {