зеркало из https://github.com/mozilla/gecko-dev.git
Bug 436703 - select all + Copy/paste in contenteditable div pastes the editable div inside itself, r=peterv
This commit is contained in:
Родитель
bd2e143dc7
Коммит
9a1b9595f3
|
@ -1399,6 +1399,10 @@ nsHTMLCopyEncoder::PromoteAncestorChain(nsCOMPtr<nsIDOMNode> *ioNode,
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMNode> frontNode, endNode, parent;
|
nsCOMPtr<nsIDOMNode> frontNode, endNode, parent;
|
||||||
PRInt32 frontOffset, endOffset;
|
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
|
// loop for as long as we can promote both endpoints
|
||||||
while (!done)
|
while (!done)
|
||||||
|
@ -1415,8 +1419,11 @@ nsHTMLCopyEncoder::PromoteAncestorChain(nsCOMPtr<nsIDOMNode> *ioNode,
|
||||||
// then we make the same attempt with the endpoint
|
// then we make the same attempt with the endpoint
|
||||||
rv = GetPromotedPoint( kEnd, *ioNode, *ioEndOffset, address_of(endNode), &endOffset, parent);
|
rv = GetPromotedPoint( kEnd, *ioNode, *ioEndOffset, address_of(endNode), &endOffset, parent);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
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;
|
done = PR_TRUE;
|
||||||
else
|
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>';
|
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");
|
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();
|
SimpleTest.finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,5 +192,7 @@ addLoadEvent(testHtmlCopyEncoder);
|
||||||
</ol>
|
</ol>
|
||||||
foo bar
|
foo bar
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div id="aContentEditable" contentEditable="true"><p>one</p><p>two</p></div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Загрузка…
Ссылка в новой задаче