Bug 436703 - select all + Copy/paste in contenteditable div pastes the editable div inside itself, r=peterv

This commit is contained in:
liucougar 2009-11-01 15:43:18 -08:00
Родитель bd2e143dc7
Коммит 9a1b9595f3
2 изменённых файлов: 20 добавлений и 2 удалений

Просмотреть файл

@ -1400,6 +1400,10 @@ nsHTMLCopyEncoder::PromoteAncestorChain(nsCOMPtr<nsIDOMNode> *ioNode,
nsCOMPtr<nsIDOMNode> frontNode, endNode, parent;
PRInt32 frontOffset, endOffset;
//save the editable state of the ioNode, so we don't promote an ancestor if it has different editable state
nsCOMPtr<nsINode> node = do_QueryInterface(*ioNode);
PRBool isEditable = node->IsEditable();
// loop for as long as we can promote both endpoints
while (!done)
{
@ -1415,8 +1419,11 @@ nsHTMLCopyEncoder::PromoteAncestorChain(nsCOMPtr<nsIDOMNode> *ioNode,
// then we make the same attempt with the endpoint
rv = GetPromotedPoint( kEnd, *ioNode, *ioEndOffset, address_of(endNode), &endOffset, parent);
NS_ENSURE_SUCCESS(rv, rv);
// if both endpoints were promoted one level, keep looping - otherwise we are done.
if ( (frontNode != parent) || (endNode != parent) )
nsCOMPtr<nsINode> frontINode = do_QueryInterface(frontNode);
// if both endpoints were promoted one level and isEditable is the same as the original node,
// keep looping - otherwise we are done.
if ( (frontNode != parent) || (endNode != parent) || (frontINode->IsEditable() != isEditable) )
done = PR_TRUE;
else
{

Просмотреть файл

@ -157,6 +157,15 @@ function testHtmlCopyEncoder () {
expected = '<ol id=\"aList\">\n <li value=\"8\">Lorem ipsum dolor</li>\n <li>sit amet, <strong>consectetuer</strong> </li>\n <li>adipiscing elit</li>\n <li>Nam eu sapien. Sed viverra lacus. Donec quis ipsum. Nunc cursus \naliquet lectus. Nunc vitae eros. Class</li>\n <li>aptent taciti</li>\n</ol>';
is(out, expected, "test list selection with a value on a LI");
//test Bug 436703
node = document.getElementById('aContentEditable');
select.selectAllChildren(node);
encoder.init(document, "text/html", de.OutputLFLineBreak | de.OutputSelectionOnly);
encoder.setSelection(select);
out = encoder.encodeToString();
expected = '<p>one</p><p>two</p>';
is(out, expected, "select all children in an contentEditable div should not select the div itself");
SimpleTest.finish();
}
@ -183,5 +192,7 @@ addLoadEvent(testHtmlCopyEncoder);
</ol>
foo bar
</div>
<div id="aContentEditable" contentEditable="true"><p>one</p><p>two</p></div>
</body>
</html>