Bug 240933 - Part 12: Avoid injecting textnodes as children of br nodes; r,a=roc

--HG--
extra : rebase_source : 5b6a4d870c1f95da0d2a1233d1648096ae599174
This commit is contained in:
Ehsan Akhgari 2010-08-13 18:58:24 -04:00
parent 8afe6b0c89
commit 578ac0b85f
2 changed files with 32 additions and 0 deletions

View File

@ -2332,6 +2332,28 @@ NS_IMETHODIMP nsEditor::InsertTextImpl(const nsAString& aStringToInsert,
}
}
}
// Sometimes, aInOutNode is the mozBR element itself. In that case, we'll
// adjust the insertion point to the previous text node, if one exists, or
// to the parent anonymous DIV.
if (nsTextEditUtils::IsMozBR(*aInOutNode) && *aInOutOffset == 0) {
nsCOMPtr<nsIDOMNode> previous;
(*aInOutNode)->GetPreviousSibling(getter_AddRefs(previous));
nodeAsText = do_QueryInterface(previous);
if (nodeAsText) {
PRUint32 length;
res = nodeAsText->GetLength(&length);
if (NS_SUCCEEDED(res)) {
*aInOutOffset = PRInt32(length);
*aInOutNode = previous;
}
} else {
nsCOMPtr<nsIDOMNode> parent;
(*aInOutNode)->GetParentNode(getter_AddRefs(parent));
if (parent == GetRoot()) {
*aInOutNode = parent;
}
}
}
}
PRInt32 offset = *aInOutOffset;
if (mInIMEMode)

View File

@ -33,6 +33,12 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=240933
synthesizeMouse(t, t.clientWidth / 2, 5, {}, window);
is(t.selectionStart, 3, "The selection should be set before the newline");
is(t.selectionEnd, 3, "The selection should be set before the newline");
t = document.getElementById("ta");
t.focus();
var val = t.value;
synthesizeKey("VK_ENTER", {});
is(t.value, val + "\n", "Pressing enter right after focusing the textarea should work");
SimpleTest.finish();
});
@ -40,6 +46,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=240933
</pre>
<textarea id="t" rows="10" cols="10">abc
</textarea>
<textarea id="ta" rows="10" cols="10">
test
</textarea>
</body>