Bug 1354002 - set defaultparagraphseparator based on pref mail.compose.default_to_paragraph. r=aceman
authorJorg K <jorgk@jorgk.com>
Wed, 05 Apr 2017 23:25:00 +0200
changeset 28384 dd97865d7a80a00490e1cf1226b05ca6d2fe18bc
parent 28383 f3926c01ebe5f4796bfbe696101c7b13e4b44e88
child 28385 064ea09a484db674bea276f4f634dd9b7bf85d24
push id1986
push userclokep@gmail.com
push dateWed, 02 Aug 2017 14:43:31 +0000
treeherdercomm-beta@b51c9adf2c9e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaceman
bugs1354002
Bug 1354002 - set defaultparagraphseparator based on pref mail.compose.default_to_paragraph. r=aceman
mail/components/compose/content/MsgComposeCommands.js
mailnews/compose/src/nsMsgCompose.cpp
--- a/mail/components/compose/content/MsgComposeCommands.js
+++ b/mail/components/compose/content/MsgComposeCommands.js
@@ -420,37 +420,20 @@ var stateListener = {
 
       if (range.startContainer != mailBody) {
         dump("Unexpected selection in NotifyComposeBodyReadyReply\n");
         return;
       }
 
       editor.enableUndo(false);
 
-      // Delete a <br> if we see one.
-      let deleted2ndBR = false;
-      let currentNode = mailBody.childNodes[start];
-      if (currentNode.nodeName == "BR") {
-        currentNode.remove();
-        currentNode = mailBody.childNodes[start];
-        if (currentNode && currentNode.nodeName == "BR") {
-          currentNode.remove();
-          deleted2ndBR = true;
-        }
-      }
-
       let pElement = editor.createElementWithDefaults("p");
       pElement.appendChild(editor.createElementWithDefaults("br"));
       editor.insertElementAtSelection(pElement, false);
 
-      if (deleted2ndBR) {
-        editor.insertElementAtSelection(
-          editor.createElementWithDefaults("br"), false);
-      }
-
       // Position into the paragraph.
       selection.collapse(pElement, 0);
 
       document.getElementById("cmd_paragraphState").setAttribute("state", "p");
 
       editor.enableUndo(true);
       editor.resetModificationCount();
     } else {
@@ -5361,19 +5344,20 @@ function InitEditor()
   // inconsistent in subject and message body.
   let eEditorMailMask = Components.interfaces.nsIPlaintextEditor.eEditorMailMask;
   editor.flags |= eEditorMailMask;
   GetMsgSubjectElement().editor.flags |= eEditorMailMask;
 
   // Control insertion of line breaks.
   editor.returnInParagraphCreatesNewParagraph =
     Services.prefs.getBoolPref("editor.CR_creates_new_p");
-  // Traditionally we want <br> elements for newlines, unless we're
-  // splitting a paragraph (which is not affected by this setting).
-  editor.document.execCommand("defaultparagraphseparator", false, "br");
+  editor.document.execCommand("defaultparagraphseparator", false,
+    gMsgCompose.composeHTML &&
+    Services.prefs.getBoolPref("mail.compose.default_to_paragraph") ?
+                               "p" : "br");
 
   editor.QueryInterface(nsIEditorStyleSheets);
   // We use addOverrideStyleSheet rather than addStyleSheet so that we get
   // a synchronous load, rather than having a late-finishing async load
   // mark our editor as modified when the user hasn't typed anything yet,
   // but that means the sheet must not @import slow things, especially
   // not over the network.
   editor.addOverrideStyleSheet("chrome://messenger/content/composerOverlay.css");
--- a/mailnews/compose/src/nsMsgCompose.cpp
+++ b/mailnews/compose/src/nsMsgCompose.cpp
@@ -646,48 +646,56 @@ nsMsgCompose::ConvertAndLoadComposeWindo
   nsCOMPtr<nsIEditorMailSupport> mailEditor (do_QueryInterface(m_editor));
   int32_t reply_on_top = 0;
   bool sig_bottom = true;
   m_identity->GetReplyOnTop(&reply_on_top);
   m_identity->GetSigBottom(&sig_bottom);
   bool sigOnTop = (reply_on_top == 1 && !sig_bottom);
   bool isForwarded = (mType == nsIMsgCompType::ForwardInline);
 
+  // When in paragraph mode, don't call InsertLineBreak() since that inserts
+  // a full paragraph instead of just a line break since we switched
+  // the default paragraph separator to "p".
+  bool paragraphMode =
+    mozilla::Preferences::GetBool("mail.compose.default_to_paragraph", false);
+
   if (aQuoted)
   {
     mInsertingQuotedContent = true;
     if (!aPrefix.IsEmpty())
     {
       if (!aHTMLEditor)
         aPrefix.AppendLiteral("\n");
 
       int32_t reply_on_top = 0;
       m_identity->GetReplyOnTop(&reply_on_top);
       if (reply_on_top == 1)
       {
-        // HTML editor eats one line break
-        if (aHTMLEditor)
+        // HTML editor eats one line break but not a whole paragraph.
+        if (aHTMLEditor && !paragraphMode)
           textEditor->InsertLineBreak();
 
         // add one newline if a signature comes before the quote, two otherwise
         bool includeSignature = true;
         bool sig_bottom = true;
         bool attachFile = false;
         nsString prefSigText;
 
         m_identity->GetSigOnReply(&includeSignature);
         m_identity->GetSigBottom(&sig_bottom);
         m_identity->GetHtmlSigText(prefSigText);
         nsresult rv = m_identity->GetAttachSignature(&attachFile);
-        if (includeSignature && !sig_bottom &&
-            ((NS_SUCCEEDED(rv) && attachFile) || !prefSigText.IsEmpty()))
-          textEditor->InsertLineBreak();
-        else {
-          textEditor->InsertLineBreak();
-          textEditor->InsertLineBreak();
+        if (!paragraphMode || !aHTMLEditor) {
+          if (includeSignature && !sig_bottom &&
+              ((NS_SUCCEEDED(rv) && attachFile) || !prefSigText.IsEmpty()))
+            textEditor->InsertLineBreak();
+          else {
+            textEditor->InsertLineBreak();
+            textEditor->InsertLineBreak();
+          }
         }
       }
 
       InsertDivWrappedTextAtSelection(aPrefix,
                                       NS_LITERAL_STRING("moz-cite-prefix"));
     }
 
     if (!aBuf.IsEmpty() && mailEditor)
@@ -707,17 +715,17 @@ nsMsgCompose::ConvertAndLoadComposeWindo
     mInsertingQuotedContent = false;
 
     (void)TagEmbeddedObjects(mailEditor);
 
     if (!aSignature.IsEmpty())
     {
       //we cannot add it on top earlier, because TagEmbeddedObjects will mark all images in the signature as "moz-do-not-send"
       if( sigOnTop )
-        m_editor->BeginningOfDocument();
+        MoveToBeginningOfDocument();
 
       if (aHTMLEditor && htmlEditor)
         htmlEditor->InsertHTML(aSignature);
       else if (htmlEditor)
       {
         textEditor->InsertLineBreak();
         InsertDivWrappedTextAtSelection(aSignature,
                                         NS_LITERAL_STRING("moz-signature"));
@@ -911,17 +919,18 @@ nsMsgCompose::ConvertAndLoadComposeWindo
           m_editor->BeginningOfDocument();
           break;
         }
 
         // place selection after mailcite
         selection->Collapse(parent, offset+1);
 
         // insert a break at current selection
-        textEditor->InsertLineBreak();
+        if (!paragraphMode || !aHTMLEditor)
+          textEditor->InsertLineBreak();
 
         // i'm not sure if you need to move the selection back to before the
         // break. expirement.
         selection->Collapse(parent, offset+1);
 
         break;
       }
 
@@ -929,17 +938,17 @@ nsMsgCompose::ConvertAndLoadComposeWindo
       {
         m_editor->SelectAll();
         break;
       }
 
       // This should set the cursor to the top!
       default:
       {
-        m_editor->BeginningOfDocument();
+        MoveToBeginningOfDocument();
         break;
       }
     }
   }
 
   nsCOMPtr<nsISelectionController> selCon;
   m_editor->GetSelectionController(getter_AddRefs(selCon));