Bug 772282 - Hold on to nodes when we delete them in nsEditor::MoveNode; r=ehsan

This commit is contained in:
Aryeh Gregor 2012-07-11 10:51:13 +03:00
parent a65acdc8c4
commit 11df0cc2ad
3 changed files with 32 additions and 3 deletions

View File

@ -0,0 +1,27 @@
<!DOCTYPE html>
<html>
<head>
<script>
function boom()
{
var root = document.documentElement;
while(root.firstChild) { root.removeChild(root.firstChild); }
var body = document.createElementNS("http://www.w3.org/1999/xhtml", "body");
body.setAttributeNS(null, "contenteditable", "true");
var img = document.createElementNS("http://www.w3.org/1999/xhtml", "img");
body.appendChild(img);
root.appendChild(body);
document.removeChild(root);
document.appendChild(root);
document.execCommand("insertText", false, "5");
document.execCommand("selectAll", false, null);
document.execCommand("insertParagraph", false, null);
document.execCommand("increasefontsize", false, null);
}
</script>
</head>
<body onload="boom();"></body>
</html>

View File

@ -16,3 +16,4 @@ load 766413.html
load 766845.xhtml
load 768765.html
needs-focus load 771749.html
load 772282.html

View File

@ -1730,10 +1730,11 @@ nsEditor::MoveNode(nsIDOMNode *aNode, nsIDOMNode *aParent, PRInt32 aOffset)
aOffset--; // this is because when we delete aNode, it will make the offsets after it off by one
}
// put aNode in new parent
res = DeleteNode(aNode);
// Hold a reference so aNode doesn't go away when we remove it (bug 772282)
nsCOMPtr<nsIDOMNode> node = aNode;
res = DeleteNode(node);
NS_ENSURE_SUCCESS(res, res);
return InsertNode(aNode, aParent, aOffset);
return InsertNode(node, aParent, aOffset);
}