Bug 484181 - spellcheck broken in contenteditable DIV with preceding empty DIV within a DIV; r=roc
--- a/editor/libeditor/html/nsHTMLEditRules.cpp
+++ b/editor/libeditor/html/nsHTMLEditRules.cpp
@@ -8014,18 +8014,20 @@ nsHTMLEditRules::RemoveEmptyNodes()
}
// now delete the empty nodes
nodeCount = arrayOfEmptyNodes.Count();
for (j = 0; j < nodeCount; j++)
{
nsCOMPtr<nsIDOMNode> delNode = arrayOfEmptyNodes[0];
arrayOfEmptyNodes.RemoveObjectAt(0);
- res = mHTMLEditor->DeleteNode(delNode);
- if (NS_FAILED(res)) return res;
+ if (mHTMLEditor->IsModifiableNode(delNode)) {
+ res = mHTMLEditor->DeleteNode(delNode);
+ NS_ENSURE_SUCCESS(res, res);
+ }
}
// now delete the empty mailcites
// this is a separate step because we want to pull out any br's and preserve them.
nodeCount = arrayOfEmptyCites.Count();
for (j = 0; j < nodeCount; j++)
{
nsCOMPtr<nsIDOMNode> delNode = arrayOfEmptyCites[0];
--- a/editor/libeditor/html/tests/Makefile.in
+++ b/editor/libeditor/html/tests/Makefile.in
@@ -46,16 +46,17 @@ include $(topsrcdir)/config/rules.mk
_TEST_FILES = \
test_bug366682.html \
test_bug432225.html \
test_bug455992.html \
test_bug456244.html \
test_bug478725.html \
test_bug480972.html \
+ test_bug484181.html \
test_bug487524.html \
test_bug525389.html \
test_bug537046.html \
test_contenteditable_focus.html \
test_select_all_without_body.html \
file_select_all_without_body.html \
$(NULL)
new file mode 100644
--- /dev/null
+++ b/editor/libeditor/html/tests/test_bug484181.html
@@ -0,0 +1,101 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=484181
+-->
+<head>
+ <title>Test for Bug 484181</title>
+ <script type="application/javascript" src="/MochiKit/packed.js"></script>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+ <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=484181">Mozilla Bug 484181</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+/** Test for Bug 484181 **/
+
+SimpleTest.waitForExplicitFinish();
+addLoadEvent(runTest);
+
+var gMisspeltWords;
+
+function getEditor() {
+ var Ci = Components.interfaces;
+ var win = window;
+ var editingSession = win.QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIWebNavigation)
+ .QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIEditingSession);
+ return editingSession.getEditorForWindow(win);
+}
+
+function getSpellCheckSelection() {
+ var editor = getEditor();
+ var selcon = editor.selectionController;
+ return selcon.getSelection(selcon.SELECTION_SPELLCHECK);
+}
+
+function append(str) {
+ netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+
+ var edit = document.getElementById("edit");
+ edit.focus();
+ var editor = getEditor();
+ var sel = editor.selection;
+ sel.selectAllChildren(edit);
+ sel.collapseToEnd();
+
+ for (var i = 0; i < str.length; ++i) {
+ synthesizeKey(str[i], {});
+ }
+}
+
+function runTest() {
+ gMisspeltWords = ["haz", "cheezburger"];
+ is(isSpellingCheckOk(), true, "All misspellings before editing are accounted for.");
+
+ var edit = document.getElementById("edit");
+ append(" becaz I'm a lolcat!");
+ SimpleTest.executeSoon(function() {
+ gMisspeltWords.push("becaz");
+ gMisspeltWords.push("lolcat");
+ is(isSpellingCheckOk(), true, "All misspellings after typing are accounted for.");
+
+ SimpleTest.finish();
+ });
+}
+
+function isSpellingCheckOk() {
+ netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+
+ var sel = getSpellCheckSelection();
+ var numWords = sel.rangeCount;
+
+ is(numWords, gMisspeltWords.length, "Correct number of misspellings and words.");
+
+ if (numWords != gMisspeltWords.length)
+ return false;
+
+ for (var i=0; i<numWords; i++) {
+ var word = sel.getRangeAt(i);
+ is (word, gMisspeltWords[i], "Misspelling is what we think it is.");
+ if (word != gMisspeltWords[i])
+ return false;
+ }
+ return true;
+}
+
+</script>
+</pre>
+
+<div><div></div><div id="edit" contenteditable="true">I can haz cheezburger</div></div>
+
+</body>
+</html>