Bug 1306060 - Fix invalid checks for <br> and clean up formatting in composer code. r=IanN
authorFrank-Rainer Grahl <frgrahl@gmx.net>
Thu, 02 Apr 2020 12:30:42 +0200
changeset 38801 01de8e37563269a3d86d481fa824b2659c26bbe8
parent 38800 5348c023ec15051e13c42900b89408eab79f16d5
child 38802 82a6cd4c38f29245a4ac8514a22cf1b69e1acf1c
push id401
push userclokep@gmail.com
push dateMon, 01 Jun 2020 20:41:59 +0000
reviewersIanN
bugs1306060
Bug 1306060 - Fix invalid checks for <br> and clean up formatting in composer code. r=IanN
editor/ui/dialogs/content/EdDialogCommon.js
--- a/editor/ui/dialogs/content/EdDialogCommon.js
+++ b/editor/ui/dialogs/content/EdDialogCommon.js
@@ -683,18 +683,17 @@ var NotAnInlineParent = [
   "tbody",
   "tfoot",
   "thead",
   "tr",
   "ul",
 ];
 
 function nodeIsBreak(editor, node) {
-  // XXX This doesn't work because .localName is lowercase (see bug 1306060).
-  return !node || node.localName == "BR" || editor.nodeIsBlock(node);
+  return !node || node.localName == 'br' || editor.nodeIsBlock(node);
 }
 
 function InsertElementAroundSelection(element) {
   var editor = GetCurrentEditor();
   editor.beginTransaction();
 
   try {
     // First get the selection as a single range
@@ -718,37 +717,37 @@ function InsertElementAroundSelection(el
       range.setEndAfter(range.endContainer);
     }
 
     if (editor.nodeIsBlock(element)) {
       // Block element parent must be a valid block
       while (!IsBlockParent.includes(range.commonAncestorContainer.localName)) {
         range.selectNode(range.commonAncestorContainer);
       }
-    } else if (!nodeIsBreak(editor, range.commonAncestorContainer)) {
-      // Fail if we're not inserting a block (use setInlineProperty instead)
-      return false;
-    } else if (
-      NotAnInlineParent.includes(range.commonAncestorContainer.localName)
-    ) {
-      // Inline element parent must not be an invalid block
-      do {
-        range.selectNode(range.commonAncestorContainer);
-      } while (
-        NotAnInlineParent.includes(range.commonAncestorContainer.localName)
-      );
     } else {
-      // Further insert block check
-      for (var i = range.startOffset; ; i++) {
-        if (i == range.endOffset) {
-          return false;
-        } else if (
-          nodeIsBreak(editor, range.commonAncestorContainer.childNodes[i])
-        ) {
-          break;
+      if (!nodeIsBreak(editor, range.commonAncestorContainer)) {
+        // Fail if we're not inserting a block (use setInlineProperty instead)
+        return false;
+      }
+      if (NotAnInlineParent.includes(range.commonAncestorContainer.localName)) {
+        // Inline element parent must not be an invalid block
+        do {
+          range.selectNode(range.commonAncestorContainer);
+        } while (
+          NotAnInlineParent.includes(range.commonAncestorContainer.localName)
+        );
+      } else {
+        // Further insert block check
+        for (var i = range.startOffset; ; i++) {
+          if (i == range.endOffset) {
+            return false;
+          }
+          if (nodeIsBreak(editor, range.commonAncestorContainer.childNodes[i])) {
+            break;
+          }
         }
       }
     }
 
     // The range may be contained by body text, which should all be selected.
     offset = range.startOffset;
     start = range.startContainer.childNodes[offset];
     if (!nodeIsBreak(editor, start)) {
@@ -779,18 +778,17 @@ function InsertElementAroundSelection(el
       editor.insertNode(start, element, element.childNodes.length);
       empty = false;
       start = next;
     }
     if (!editor.nodeIsBlock(element)) {
       editor.setShouldTxnSetSelection(true);
     } else {
       // Also move a trailing <br>
-      // XXX This doesn't work because .localName is lowercase (see bug 1306060).
-      if (start && start.localName == "BR") {
+      if (start && start.localName == "br") {
         editor.deleteNode(start);
         editor.insertNode(start, element, element.childNodes.length);
         empty = false;
       }
       // Still nothing? Insert a <br> so the node is not empty
       if (empty) {
         editor.insertNode(
           editor.createElementWithDefaults("br"),