Bug 785528 - Don't allow deletion of doctype nodes in the markup panel. r=jwalker
authorDave Camp <dcamp@mozilla.com>
Fri, 24 Aug 2012 17:59:48 -0700
changeset 105429 4c3e82b3dcaf9afbac95ef95fff6b17b7fa70110
parent 105428 45ec9c8d4f272606830cf8e6841f727cb02e66bd
child 105430 5fa145ef906a778d1a1729ecbaa40884926c5ff5
push id55
push usershu@rfrn.org
push dateThu, 30 Aug 2012 01:33:09 +0000
reviewersjwalker
bugs785528
milestone17.0a1
Bug 785528 - Don't allow deletion of doctype nodes in the markup panel. r=jwalker
browser/devtools/markupview/MarkupView.jsm
--- a/browser/devtools/markupview/MarkupView.jsm
+++ b/browser/devtools/markupview/MarkupView.jsm
@@ -131,21 +131,17 @@ MarkupView.prototype = {
     if (aEvent.target.tagName.toLowerCase() === "input" ||
         aEvent.target.tagName.toLowerCase() === "textarea") {
       return;
     }
 
     switch(aEvent.keyCode) {
       case Ci.nsIDOMKeyEvent.DOM_VK_DELETE:
       case Ci.nsIDOMKeyEvent.DOM_VK_BACK_SPACE:
-        let node = this._selectedContainer.node;
-        let doc = nodeDocument(node);
-        if (node != doc && node != doc.documentElement) {
-          this.deleteNode(this._selectedContainer.node);
-        }
+        this.deleteNode(this._selectedContainer.node);
         break;
       case Ci.nsIDOMKeyEvent.DOM_VK_HOME:
         this.navigate(this._containers.get(this._rootNode.firstChild));
         break;
       case Ci.nsIDOMKeyEvent.DOM_VK_LEFT:
         this.collapseNode(this._selectedContainer.node);
         break;
       case Ci.nsIDOMKeyEvent.DOM_VK_RIGHT:
@@ -199,16 +195,23 @@ MarkupView.prototype = {
   },
 
   /**
    * Delete a node from the DOM.
    * This is an undoable action.
    */
   deleteNode: function MC__deleteNode(aNode)
   {
+    let doc = nodeDocument(node);
+    if (node === doc ||
+        node === doc.documentElement ||
+        node.nodeType == Ci.nsIDOMNode.DOCUMENT_TYPE_NODE) {
+      return;
+    }
+
     let parentNode = aNode.parentNode;
     let sibling = aNode.nextSibling;
 
     this.undo.do(function() {
       parentNode.removeChild(aNode);
     }, function() {
       parentNode.insertBefore(aNode, sibling);
     });