Bug 680279 - Splitting Gmail rich-text list with Enter misplaces the caret; r=ehsan

The patch for bug 674861 has introduced a regression.
When a list is splitted, a new paragraph should inserted before the new list.
This commit is contained in:
Fabien Cazenave 2011-08-19 18:14:04 -04:00
parent 95d7152dc7
commit 51ba25e02c
2 changed files with 102 additions and 34 deletions

View File

@ -6789,6 +6789,12 @@ nsHTMLEditRules::ReturnInListItem(nsISelection *aSelection,
NS_ENSURE_SUCCESS(res, res);
if (isEmpty && (rootNode != list) && mReturnInEmptyLIKillsList)
{
// get the list offset now -- before we might eventually split the list
nsCOMPtr<nsIDOMNode> listparent;
PRInt32 offset;
res = nsEditor::GetNodeLocation(list, address_of(listparent), &offset);
NS_ENSURE_SUCCESS(res, res);
// are we the last list item in the list?
PRBool bIsLast;
res = mHTMLEditor->IsLastEditableChild(aListItem, &bIsLast);
@ -6802,10 +6808,6 @@ nsHTMLEditRules::ReturnInListItem(nsISelection *aSelection,
}
// 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 so, move this list item out of this list and into the grandparent list

View File

@ -13,29 +13,57 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=674861
<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>
<section id="test1">
<h2> Editable Bullet List </h2>
<ul contenteditable>
<li> item A </li>
<li> item B </li>
<li> item C </li>
</ul>
<h2> Ordered List </h2>
<ol contenteditable>
<li> item 1 </li>
<li> item 2 </li>
<li> item 3 </li>
</ol>
<h2> Editable Ordered List </h2>
<ol contenteditable>
<li> item A </li>
<li> item B </li>
<li> item C </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>
<h2> Editable Definition List </h2>
<dl contenteditable>
<dt> term A </dt>
<dd> definition A </dd>
<dt> term B </dt>
<dd> definition B </dd>
<dt> term C </dt>
<dd> definition C </dd>
</dl>
</section>
<section id="test2" contenteditable>
<h2> Bullet List In Editable Section </h2>
<ul>
<li> item A </li>
<li> item B </li>
<li> item C </li>
</ul>
<h2> Ordered List In Editable Section </h2>
<ol>
<li> item A </li>
<li> item B </li>
<li> item C </li>
</ol>
<h2> Definition List In Editable Section </h2>
<dl>
<dt> term A </dt>
<dd> definition A </dd>
<dt> term B </dt>
<dd> definition B </dd>
<dt> term C </dt>
<dd> definition C </dd>
</dl>
</section>
</div>
<pre id="test">
@ -82,34 +110,72 @@ function try2split(element, caretPos) {
}
function runTests() {
const ul = document.querySelector("#content ul");
const ol = document.querySelector("#content ol");
const dl = document.querySelector("#content dl");
const test1 = document.getElementById("test1");
const test2 = document.getElementById("test2");
// -----------------------------------------------------------------------
// #test1: editable lists should NOT be splittable
// -----------------------------------------------------------------------
const ul = test1.querySelector("ul");
const ol = test1.querySelector("ol");
const dl = test1.querySelector("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(test1.querySelectorAll("ul").length, 1,
"The <ul contenteditable> 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(test1.querySelectorAll("ol").length, 1,
"The <ol contenteditable> 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(test1.querySelectorAll("dl").length, 1,
"The <dl contenteditable> list should not be splittable.");
is(dl.querySelectorAll("dt").length, 5,
"Two new <dt> elements should have been created.");
// -----------------------------------------------------------------------
// #test2: lists in editable blocks should be splittable
// -----------------------------------------------------------------------
test2.focus();
// bullet list
try2split(test2.querySelector("ul li"), CARET_END);
is(test2.querySelectorAll("ul").length, 2,
"The <ul> list should have been splitted.");
is(test2.querySelectorAll("ul li").length, 3,
"No new <li> element should have been created.");
is(test2.querySelectorAll("ul+p").length, 1,
"A new paragraph should have been created.");
// ordered list
try2split(test2.querySelector("ol li"), CARET_END);
is(test2.querySelectorAll("ol").length, 2,
"The <ol> list should have been splitted.");
is(test2.querySelectorAll("ol li").length, 3,
"No new <li> element should have been created.");
is(test2.querySelectorAll("ol+p").length, 1,
"A new paragraph should have been created.");
// definition list
try2split(test2.querySelector("dl dd"), CARET_END);
is(test2.querySelectorAll("dl").length, 2,
"The <dl> list should have been splitted.");
is(test2.querySelectorAll("dt").length, 3,
"No new <dt> element should have been created.");
is(test2.querySelectorAll("dl+p").length, 1,
"A new paragraph should have been created.");
// done
SimpleTest.finish();
}