зеркало из https://github.com/mozilla/gecko-dev.git
Move 'bDidInsert' inside the loop so it correctly reflects if the current node was inserted. b=480972 r+sr=peterv
This commit is contained in:
Родитель
b625b36e62
Коммит
860d8f6828
|
@ -501,7 +501,6 @@ nsHTMLEditor::InsertHTMLWithContext(const nsAString & aInputString,
|
|||
}
|
||||
|
||||
// Loop over the node list and paste the nodes:
|
||||
PRBool bDidInsert = PR_FALSE;
|
||||
nsCOMPtr<nsIDOMNode> parentBlock, lastInsertNode, insertedContextParent;
|
||||
PRInt32 listCount = nodeList.Count();
|
||||
PRInt32 j;
|
||||
|
@ -512,6 +511,7 @@ nsHTMLEditor::InsertHTMLWithContext(const nsAString & aInputString,
|
|||
|
||||
for (j=0; j<listCount; j++)
|
||||
{
|
||||
PRBool bDidInsert = PR_FALSE;
|
||||
nsCOMPtr<nsIDOMNode> curNode = nodeList[j];
|
||||
|
||||
NS_ENSURE_TRUE(curNode, NS_ERROR_FAILURE);
|
||||
|
@ -616,7 +616,6 @@ nsHTMLEditor::InsertHTMLWithContext(const nsAString & aInputString,
|
|||
|
||||
if (!bDidInsert || NS_FAILED(res))
|
||||
{
|
||||
|
||||
// try to insert
|
||||
res = InsertNodeAtPoint(curNode, address_of(parentNode), &offsetOfNewNode, PR_TRUE);
|
||||
if (NS_SUCCEEDED(res))
|
||||
|
@ -644,7 +643,7 @@ nsHTMLEditor::InsertHTMLWithContext(const nsAString & aInputString,
|
|||
curNode = parent;
|
||||
}
|
||||
}
|
||||
if (bDidInsert)
|
||||
if (lastInsertNode)
|
||||
{
|
||||
res = GetNodeLocation(lastInsertNode, address_of(parentNode), &offsetOfNewNode);
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
|
|
|
@ -50,6 +50,7 @@ _TEST_FILES = \
|
|||
test_bug455992.html \
|
||||
test_bug456244.html \
|
||||
test_bug478725.html \
|
||||
test_bug480972.html \
|
||||
$(NULL)
|
||||
|
||||
libs:: $(_TEST_FILES)
|
||||
|
|
|
@ -0,0 +1,101 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html><head>
|
||||
<title>Test for bug 480972</title>
|
||||
<style src="/tests/SimpleTest/test.css" type="text/css"></style>
|
||||
<script type="application/javascript" src="/MochiKit/packed.js"></script>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
|
||||
|
||||
<script class="testbody" type="application/javascript">
|
||||
|
||||
function runTest() {
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
|
||||
function verifyContent(s) {
|
||||
var e = document.getElementById('i1');
|
||||
var doc = e.contentDocument;
|
||||
is(doc.body.innerHTML, s, "");
|
||||
}
|
||||
|
||||
function pasteInto(html,target_id) {
|
||||
var e = document.getElementById('i1');
|
||||
var doc = e.contentDocument;
|
||||
doc.designMode = "on";
|
||||
doc.body.innerHTML = html;
|
||||
doc.defaultView.focus();
|
||||
if (target_id)
|
||||
e = doc.getElementById(target_id);
|
||||
else
|
||||
e = doc.body;
|
||||
var selection = doc.defaultView.getSelection();
|
||||
selection.removeAllRanges();
|
||||
selection.selectAllChildren(e);
|
||||
selection.collapseToEnd();
|
||||
doc.execCommand("paste", false, null);
|
||||
return e;
|
||||
}
|
||||
|
||||
function copyToClipBoard(s,asHTML,target_id) {
|
||||
var e = document.getElementById('i2');
|
||||
var doc = e.contentDocument;
|
||||
if (asHTML) {
|
||||
doc.body.innerHTML = s;
|
||||
} else {
|
||||
var text = doc.createTextNode(s);
|
||||
doc.body.appendChild(text);
|
||||
}
|
||||
doc.designMode = "on";
|
||||
doc.defaultView.focus();
|
||||
var selection = doc.defaultView.getSelection();
|
||||
selection.removeAllRanges();
|
||||
if (!target_id) {
|
||||
selection.selectAllChildren(doc.body);
|
||||
} else {
|
||||
var range = document.createRange();
|
||||
range.selectNode(doc.getElementById(target_id));
|
||||
selection.addRange(range);
|
||||
}
|
||||
doc.execCommand("copy", false, null);
|
||||
return e;
|
||||
}
|
||||
|
||||
copyToClipBoard('<span>Hello</span><span>Kitty</span>', true);
|
||||
pasteInto('');
|
||||
verifyContent('<span>Hello</span><span>Kitty</span>');
|
||||
|
||||
copyToClipBoard("<dl><dd>Hello Kitty</dd></dl><span>Hello</span><span>Kitty</span>", true);
|
||||
pasteInto('<ol><li id="paste_here">X</li></ol>',"paste_here");
|
||||
verifyContent('<ol><li id="paste_here">X<dl><dd>Hello Kitty</dd></dl><span>Hello</span><span>Kitty</span></li></ol>');
|
||||
|
||||
// The following test doesn't do what I expected, because the special handling
|
||||
// of IsList nodes in nsHTMLEditor::InsertHTMLWithContext simply removes
|
||||
// non-list/item children. See bug 481177.
|
||||
// copyToClipBoard("<ol><li>Hello Kitty</li><span>Hello</span></ol>", true);
|
||||
// pasteInto('<ol><li id="paste_here">X</li></ol>',"paste_here");
|
||||
// verifyContent('<ol><li id="paste_here">X</li><li>Hello Kitty</li><span>Hello</span></ol>');
|
||||
|
||||
copyToClipBoard("<pre>Kitty</pre><span>Hello</span>", true);
|
||||
pasteInto('<pre id="paste_here">Hello </pre>',"paste_here");
|
||||
verifyContent('<pre id="paste_here">Hello Kitty<span>Hello</span></pre>');
|
||||
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
addLoadEvent(runTest);
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=480972">Mozilla Bug 480972</a>
|
||||
<p id="display"></p>
|
||||
|
||||
<pre id="test">
|
||||
</pre>
|
||||
|
||||
|
||||
<iframe id="i1" width="200" height="100" src="about:blank"></iframe><br>
|
||||
<iframe id="i2" width="200" height="100" src="about:blank"></iframe><br>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
Загрузка…
Ссылка в новой задаче