Bug 1250010 - Fix nsHTMLEditRules::ReturnInParagraph(). r=ehsan

This commit is contained in:
Jorg K 2016-02-24 13:43:00 +01:00
Родитель cff547515b
Коммит bf7203ac32
3 изменённых файлов: 68 добавлений и 4 удалений

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

@ -6475,7 +6475,10 @@ nsHTMLEditRules::ReturnInParagraph(Selection* aSelection,
bool doesCRCreateNewP = mHTMLEditor->GetReturnInParagraphCreatesNewParagraph();
bool newBRneeded = false;
bool newSelNode = false;
nsCOMPtr<nsIDOMNode> sibling;
nsCOMPtr<nsIDOMNode> selNode = aNode;
int32_t selOffset = aOffset;
NS_ENSURE_STATE(mHTMLEditor);
if (aNode == aPara && doesCRCreateNewP) {
@ -6513,7 +6516,7 @@ nsHTMLEditRules::ReturnInParagraph(Selection* aSelection,
nsCOMPtr<nsIDOMNode> tmp;
res = mEditor->SplitNode(aNode, aOffset, getter_AddRefs(tmp));
NS_ENSURE_SUCCESS(res, res);
aNode = tmp;
selNode = tmp;
}
newBRneeded = true;
@ -6522,7 +6525,7 @@ nsHTMLEditRules::ReturnInParagraph(Selection* aSelection,
} else {
// not in a text node.
// is there a BR prior to it?
nsCOMPtr<nsIDOMNode> nearNode, selNode = aNode;
nsCOMPtr<nsIDOMNode> nearNode;
NS_ENSURE_STATE(mHTMLEditor);
res = mHTMLEditor->GetPriorHTMLNode(aNode, aOffset, address_of(nearNode));
NS_ENSURE_SUCCESS(res, res);
@ -6537,6 +6540,9 @@ nsHTMLEditRules::ReturnInParagraph(Selection* aSelection,
if (!nearNode || !mHTMLEditor->IsVisBreak(nearNode) ||
nsTextEditUtils::HasMozAttr(nearNode)) {
newBRneeded = true;
parent = aNode;
offset = 0;
newSelNode = true;
}
}
if (!newBRneeded) {
@ -6551,10 +6557,14 @@ nsHTMLEditRules::ReturnInParagraph(Selection* aSelection,
NS_ENSURE_STATE(mHTMLEditor);
res = mHTMLEditor->CreateBR(parent, offset, address_of(brNode));
sibling = brNode;
if (newSelNode) {
// We split the parent after the br we've just inserted.
selNode = parent;
selOffset = 1;
}
}
nsCOMPtr<nsIDOMNode> selNode = aNode;
*aHandled = true;
return SplitParagraph(aPara, sibling, aSelection, address_of(selNode), &aOffset);
return SplitParagraph(aPara, sibling, aSelection, address_of(selNode), &selOffset);
}
///////////////////////////////////////////////////////////////////////////

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

@ -30,6 +30,7 @@ skip-if = buildapp == 'mulet'
[test_bug1154791.html]
[test_bug1248128.html]
[test_bug1248185.html]
[test_bug1250010.html]
[test_composition_event_created_in_chrome.html]
[test_contenteditable_text_input_handling.html]
[test_dragdrop.html]

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

@ -0,0 +1,53 @@
<!DOCTYPE>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1250010
-->
<head>
<title>Test for Bug 1250010</title>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
</head>
<body>
<div id="display">
</div>
<div id="content" contenteditable><p><b><font color="red">1234567890</font></b></p></div>
<pre id="test">
</pre>
<script class="testbody" type="application/javascript">
/** Test for Bug 1250010 **/
SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(function() {
var div = document.getElementById("content");
div.focus();
synthesizeMouseAtCenter(div, {});
var sel = window.getSelection();
var selRange = sel.getRangeAt(0);
is(selRange.endContainer.nodeName, "#text", "selection should be at the end of text node");
is(selRange.endOffset, 10, "offset should be 10");
synthesizeKey("VK_RETURN", {});
synthesizeKey("VK_RETURN", {});
synthesizeKey("b", {});
synthesizeKey("VK_UP", {});
synthesizeKey("a", {});
is(div.innerHTML, "<p><b><font color=\"red\">1234567890</font></b></p>" +
"<p><b><font color=\"red\">a<br></font></b></p>" +
"<p><b><font color=\"red\">b<br></font></b></p>",
"unexpected HTML");
SimpleTest.finish();
});
</script>
</body>
</html>