Bug 487524. Joining a list to its parent should be a no-op. r+sr=peterv

--HG--
extra : rebase_source : bc62f18f6ef25dcabd5a48caad547be2a209662d
This commit is contained in:
Mats Palmgren 2009-05-13 21:45:38 +12:00
Родитель 90150b0ee9
Коммит 8c365bb4db
3 изменённых файлов: 81 добавлений и 3 удалений

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

@ -2670,6 +2670,15 @@ nsHTMLEditRules::JoinBlocks(nsCOMPtr<nsIDOMNode> *aLeftBlock,
return NS_OK;
}
// Joining a list item to its parent is a NOP.
if (nsHTMLEditUtils::IsList(*aLeftBlock) && nsHTMLEditUtils::IsListItem(*aRightBlock))
{
nsCOMPtr<nsIDOMNode> rightParent;
(*aRightBlock)->GetParentNode(getter_AddRefs(rightParent));
if (rightParent == *aLeftBlock)
return NS_OK;
}
// special rule here: if we are trying to join list items, and they are in different lists,
// join the lists instead.
PRBool bMergeLists = PR_FALSE;
@ -2816,7 +2825,7 @@ nsHTMLEditRules::JoinBlocks(nsCOMPtr<nsIDOMNode> *aLeftBlock,
* nsIDOMNode *aLeftBlock parent to receive moved content
* nsIDOMNode *aRightBlock parent to provide moved content
* PRInt32 aLeftOffset offset in aLeftBlock to move content to
* PRInt32 aRightOffset offset in aLeftBlock to move content to
* PRInt32 aRightOffset offset in aRightBlock to move content from
*/
nsresult
nsHTMLEditRules::MoveBlock(nsIDOMNode *aLeftBlock, nsIDOMNode *aRightBlock, PRInt32 aLeftOffset, PRInt32 aRightOffset)
@ -2854,7 +2863,7 @@ nsHTMLEditRules::MoveBlock(nsIDOMNode *aLeftBlock, nsIDOMNode *aRightBlock, PRIn
* inserted content.
* nsIDOMNode *aSource the selection.
* nsIDOMNode *aDest parent to receive moved content
* PRInt32 *aOffset offset in aNewParent to move content to
* PRInt32 *aOffset offset in aDest to move content to
*/
nsresult
nsHTMLEditRules::MoveNodeSmart(nsIDOMNode *aSource, nsIDOMNode *aDest, PRInt32 *aOffset)
@ -2891,13 +2900,14 @@ nsHTMLEditRules::MoveNodeSmart(nsIDOMNode *aSource, nsIDOMNode *aDest, PRInt32 *
* inserted content. aSource is deleted.
* nsIDOMNode *aSource the selection.
* nsIDOMNode *aDest parent to receive moved content
* PRInt32 *aOffset offset in aNewParent to move content to
* PRInt32 *aOffset offset in aDest to move content to
*/
nsresult
nsHTMLEditRules::MoveContents(nsIDOMNode *aSource, nsIDOMNode *aDest, PRInt32 *aOffset)
{
if (!aSource || !aDest || !aOffset) return NS_ERROR_NULL_POINTER;
if (aSource == aDest) return NS_ERROR_ILLEGAL_VALUE;
NS_ASSERTION(!mHTMLEditor->IsTextNode(aSource), "#text does not have contents");
nsCOMPtr<nsIDOMNode> child;
nsAutoString tag;

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

@ -51,6 +51,7 @@ _TEST_FILES = \
test_bug456244.html \
test_bug478725.html \
test_bug480972.html \
test_bug487524.html \
$(NULL)
libs:: $(_TEST_FILES)

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

@ -0,0 +1,67 @@
<!DOCTYPE HTML>
<html><head>
<title>Test for bug 487524</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 setupIframe(e,html,focus_id) {
var doc = e.contentDocument;
doc.body.innerHTML = html;
doc.designMode = "on";
e = doc.getElementById(focus_id);
doc.defaultView.focus();
if (e) e.focus();
return e;
}
var i1 = document.getElementById('i1')
var li1 = setupIframe(i1,'<ul><li id="li1">one</li><li>two</li><ul><li>a</li></ul></ul>','li1')
var doc = li1.ownerDocument;
var selection = doc.defaultView.getSelection();
selection.removeAllRanges();
var range = doc.createRange();
range.setStart(li1,0);
range.setEnd(li1.nextSibling,0);
selection.addRange(range);
sendKey('delete', li1);
is(doc.body.innerHTML,'<ul><li>two</li><ul><li>a</li></ul></ul>','delete 1st LI');
var li2 = setupIframe(i1,'<ul><li id="li2">two</li><ul><li>a</li></ul></ul>','li2')
selection = doc.defaultView.getSelection();
selection.removeAllRanges();
range = doc.createRange();
range.setStart(li2,0);
range.setEnd(li2.nextSibling.firstChild,0);
selection.addRange(range);
sendKey('delete', li2);
is(doc.body.innerHTML,'<ul><ul><li>a</li></ul></ul>','delete 2nd LI');
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
addLoadEvent(runTest);
</script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=487524">Mozilla Bug 487524</a>
<p id="display"></p>
<pre id="test">
</pre>
<iframe id="i1" width="200" height="100" src="about:blank"></iframe><br>
</body>
</html>