 diff --git a/editor/libeditor/nsHTMLEditRules.cpp b/editor/libeditor/nsHTMLEditRules.cpp
 --- a/editor/libeditor/nsHTMLEditRules.cpp
 +++ b/editor/libeditor/nsHTMLEditRules.cpp
-@@ -1388,55 +1388,18 @@ nsHTMLEditRules::WillInsertText(EditActi
+@@ -482,17 +482,20 @@ nsHTMLEditRules::AfterEditInner(EditActi
+          action != EditAction::insertIMEText) )
+     {
+       NS_ENSURE_STATE(mHTMLEditor);
+       res = mHTMLEditor->CollapseAdjacentTextNodes(mDocChangeRange);
+       NS_ENSURE_SUCCESS(res, res);
+     }
+ 
+     // clean up any empty nodes in the selection
+-    res = RemoveEmptyNodes();
++    if ((action != EditAction::insertNode) &&
++        (action != EditAction::htmlPaste) &&
++        (action != EditAction::loadHTML))
++      res = RemoveEmptyNodes();
+     NS_ENSURE_SUCCESS(res, res);
+ 
+     // attempt to transform any unneeded nbsp's into spaces after doing various operations
+     if ((action == EditAction::insertText) ||
+         (action == EditAction::insertIMEText) ||
+         (action == EditAction::deleteSelection) ||
+         (action == EditAction::insertBreak) ||
+         (action == EditAction::htmlPaste ||
+@@ -1388,55 +1391,18 @@ nsHTMLEditRules::WillInsertText(EditActi
      int32_t pos = 0;
      NS_NAMED_LITERAL_STRING(newlineStr, LFSTR);
  

 // ReturnInListItem: do the right thing for returns pressed in list items
 //
 nsresult
@@ -6706,16 +6670,19 @@ nsHTMLEditRules::ReturnInListItem(Select
     }
     else
     {

     if (nsCocoaFeatures::OnElCapitanOrLater()) {
       [effectView setMaterial:NSVisualEffectMaterialMenu];
     } else {
diff --git a/widget/cocoa/moz.build b/widget/cocoa/moz.build
--- a/widget/cocoa/moz.build
+++ b/widget/cocoa/moz.build
