зеркало из https://github.com/mozilla/pjs.git
Bug 674861 - contentEditable lists should not be splittable; r=ehsan
In design mode, pressing [Return] twice in a list (ol, ul, dl) splits the list and inserts a paragraph. When the list is the active editing host, it should not be split.
This commit is contained in:
Родитель
8d35bc5104
Коммит
0befe25f5a
|
@ -6771,19 +6771,21 @@ nsHTMLEditRules::ReturnInListItem(nsISelection *aSelection,
|
||||||
NS_PRECONDITION(PR_TRUE == nsHTMLEditUtils::IsListItem(aListItem),
|
NS_PRECONDITION(PR_TRUE == nsHTMLEditUtils::IsListItem(aListItem),
|
||||||
"expected a list item and didn't get one");
|
"expected a list item and didn't get one");
|
||||||
|
|
||||||
|
// get the listitem parent and the active editing host.
|
||||||
|
nsIContent* rootContent = mHTMLEditor->GetActiveEditingHost();
|
||||||
|
nsCOMPtr<nsIDOMNode> rootNode = do_QueryInterface(rootContent);
|
||||||
|
nsCOMPtr<nsIDOMNode> list;
|
||||||
|
PRInt32 itemOffset;
|
||||||
|
res = nsEditor::GetNodeLocation(aListItem, address_of(list), &itemOffset);
|
||||||
|
NS_ENSURE_SUCCESS(res, res);
|
||||||
|
|
||||||
// if we are in an empty listitem, then we want to pop up out of the list
|
// if we are in an empty listitem, then we want to pop up out of the list
|
||||||
|
// but only if prefs says it's ok and if the parent isn't the active editing host.
|
||||||
PRBool isEmpty;
|
PRBool isEmpty;
|
||||||
res = IsEmptyBlock(aListItem, &isEmpty, PR_TRUE, PR_FALSE);
|
res = IsEmptyBlock(aListItem, &isEmpty, PR_TRUE, PR_FALSE);
|
||||||
NS_ENSURE_SUCCESS(res, res);
|
NS_ENSURE_SUCCESS(res, res);
|
||||||
if (isEmpty && mReturnInEmptyLIKillsList) // but only if prefs says it's ok
|
if (isEmpty && (rootNode != list) && mReturnInEmptyLIKillsList)
|
||||||
{
|
{
|
||||||
nsCOMPtr<nsIDOMNode> list, listparent;
|
|
||||||
PRInt32 offset, itemOffset;
|
|
||||||
res = nsEditor::GetNodeLocation(aListItem, address_of(list), &itemOffset);
|
|
||||||
NS_ENSURE_SUCCESS(res, res);
|
|
||||||
res = nsEditor::GetNodeLocation(list, address_of(listparent), &offset);
|
|
||||||
NS_ENSURE_SUCCESS(res, res);
|
|
||||||
|
|
||||||
// are we the last list item in the list?
|
// are we the last list item in the list?
|
||||||
PRBool bIsLast;
|
PRBool bIsLast;
|
||||||
res = mHTMLEditor->IsLastEditableChild(aListItem, &bIsLast);
|
res = mHTMLEditor->IsLastEditableChild(aListItem, &bIsLast);
|
||||||
|
@ -6795,7 +6797,12 @@ nsHTMLEditRules::ReturnInListItem(nsISelection *aSelection,
|
||||||
res = mHTMLEditor->SplitNode(list, itemOffset, getter_AddRefs(tempNode));
|
res = mHTMLEditor->SplitNode(list, itemOffset, getter_AddRefs(tempNode));
|
||||||
NS_ENSURE_SUCCESS(res, res);
|
NS_ENSURE_SUCCESS(res, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
// are we in a sublist?
|
// are we in a sublist?
|
||||||
|
nsCOMPtr<nsIDOMNode> listparent;
|
||||||
|
PRInt32 offset;
|
||||||
|
res = nsEditor::GetNodeLocation(list, address_of(listparent), &offset);
|
||||||
|
NS_ENSURE_SUCCESS(res, res);
|
||||||
if (nsHTMLEditUtils::IsList(listparent)) //in a sublist
|
if (nsHTMLEditUtils::IsList(listparent)) //in a sublist
|
||||||
{
|
{
|
||||||
// if so, move this list item out of this list and into the grandparent list
|
// if so, move this list item out of this list and into the grandparent list
|
||||||
|
|
|
@ -81,6 +81,7 @@ _TEST_FILES = \
|
||||||
test_bug629845.html \
|
test_bug629845.html \
|
||||||
test_bug640321.html \
|
test_bug640321.html \
|
||||||
test_bug668599.html \
|
test_bug668599.html \
|
||||||
|
test_bug674861.html \
|
||||||
test_CF_HTML_clipboard.html \
|
test_CF_HTML_clipboard.html \
|
||||||
test_contenteditable_focus.html \
|
test_contenteditable_focus.html \
|
||||||
test_htmleditor_keyevent_handling.html \
|
test_htmleditor_keyevent_handling.html \
|
||||||
|
|
|
@ -0,0 +1,120 @@
|
||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
<!--
|
||||||
|
https://bugzilla.mozilla.org/show_bug.cgi?id=674861
|
||||||
|
-->
|
||||||
|
<head>
|
||||||
|
<title>Test for Bug 674861</title>
|
||||||
|
<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>
|
||||||
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=674861">Mozilla Bug 674861</a>
|
||||||
|
<p id="display"></p>
|
||||||
|
<div id="content">
|
||||||
|
<h2> Bullet List </h2>
|
||||||
|
<ul contenteditable>
|
||||||
|
<li> item 1 </li>
|
||||||
|
<li> item 2 </li>
|
||||||
|
<li> item 3 </li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<h2> Ordered List </h2>
|
||||||
|
<ol contenteditable>
|
||||||
|
<li> item 1 </li>
|
||||||
|
<li> item 2 </li>
|
||||||
|
<li> item 3 </li>
|
||||||
|
</ol>
|
||||||
|
|
||||||
|
<h2> Definition List </h2>
|
||||||
|
<dl contenteditable>
|
||||||
|
<dt> term 1 </dt>
|
||||||
|
<dd> definition 1 </dd>
|
||||||
|
<dt> term 2 </dt>
|
||||||
|
<dd> definition 2 </dd>
|
||||||
|
<dt> term 3 </dt>
|
||||||
|
<dd> definition 3 </dd>
|
||||||
|
</dl>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<pre id="test">
|
||||||
|
<script type="application/javascript">
|
||||||
|
|
||||||
|
/** Test for Bug 674861 **/
|
||||||
|
SimpleTest.waitForExplicitFinish();
|
||||||
|
SimpleTest.waitForFocus(runTests);
|
||||||
|
|
||||||
|
const CARET_BEGIN = 0;
|
||||||
|
const CARET_MIDDLE = 1;
|
||||||
|
const CARET_END = 2;
|
||||||
|
|
||||||
|
function try2split(element, caretPos) {
|
||||||
|
// compute the requested position
|
||||||
|
var len = element.textContent.length;
|
||||||
|
var pos = -1;
|
||||||
|
switch (caretPos) {
|
||||||
|
case CARET_BEGIN:
|
||||||
|
pos = 0;
|
||||||
|
break;
|
||||||
|
case CARET_MIDDLE:
|
||||||
|
pos = Math.floor(len/2);
|
||||||
|
break;
|
||||||
|
case CARET_END:
|
||||||
|
pos = len;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// put the caret on the requested position
|
||||||
|
var sel = window.getSelection();
|
||||||
|
for (var i = 0; i < sel.rangeCount; i++) {
|
||||||
|
var range = sel.getRangeAt(i);
|
||||||
|
sel.removeRange(range);
|
||||||
|
}
|
||||||
|
range = document.createRange();
|
||||||
|
range.setStart(element.firstChild, pos);
|
||||||
|
range.setEnd(element.firstChild, pos);
|
||||||
|
sel.addRange(range);
|
||||||
|
|
||||||
|
// simulates two [Return] keypresses
|
||||||
|
synthesizeKey("VK_RETURN", {});
|
||||||
|
synthesizeKey("VK_RETURN", {});
|
||||||
|
}
|
||||||
|
|
||||||
|
function runTests() {
|
||||||
|
const ul = document.querySelector("#content ul");
|
||||||
|
const ol = document.querySelector("#content ol");
|
||||||
|
const dl = document.querySelector("#content dl");
|
||||||
|
|
||||||
|
// bullet list
|
||||||
|
ul.focus();
|
||||||
|
try2split(ul.querySelector("li"), CARET_END);
|
||||||
|
is(document.querySelectorAll("#content ul").length, 1,
|
||||||
|
"The <ul> list should not be splittable.");
|
||||||
|
is(ul.querySelectorAll("li").length, 5,
|
||||||
|
"Two new <li> elements should have been created.");
|
||||||
|
|
||||||
|
// ordered list
|
||||||
|
ol.focus();
|
||||||
|
try2split(ol.querySelector("li"), CARET_END);
|
||||||
|
is(document.querySelectorAll("#content ol").length, 1,
|
||||||
|
"The <ol> list should not be splittable.");
|
||||||
|
is(ol.querySelectorAll("li").length, 5,
|
||||||
|
"Two new <li> elements should have been created.");
|
||||||
|
|
||||||
|
// definition list
|
||||||
|
dl.focus();
|
||||||
|
try2split(dl.querySelector("dd"), CARET_END);
|
||||||
|
is(document.querySelectorAll("#content dl").length, 1,
|
||||||
|
"The <dl> list should not be splittable.");
|
||||||
|
is(dl.querySelectorAll("dt").length, 5,
|
||||||
|
"Two new <dt> elements should have been created.");
|
||||||
|
|
||||||
|
// done
|
||||||
|
SimpleTest.finish();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</pre>
|
||||||
|
</body>
|
||||||
|
</html>
|
Загрузка…
Ссылка в новой задаче