Bug 832025 - Clear the cached styles and type-in state props when pressing Enter inside a heading or a list item; r=ehsan
authorDaniel Glazman <daniel@glazman.org>
Sat, 19 Jan 2013 09:43:01 -0500
changeset 119362 8a294f8775149c32c785ddc599014ebf205d16c9
parent 119361 ec597237c8fedaa1065fc0f8bece9c2eccc359eb
child 119363 8472e5898021a48e06e3bb3656e269ad22cc2b05
push id24197
push userryanvm@gmail.com
push dateSun, 20 Jan 2013 05:25:28 +0000
treeherdermozilla-central@1d122eaa9070 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs832025
milestone21.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 832025 - Clear the cached styles and type-in state props when pressing Enter inside a heading or a list item; r=ehsan
editor/libeditor/html/nsHTMLEditRules.cpp
editor/libeditor/html/tests/Makefile.in
editor/libeditor/html/tests/test_bug832025.html
editor/libeditor/html/tests/test_bug832025_2.html
--- a/editor/libeditor/html/nsHTMLEditRules.cpp
+++ b/editor/libeditor/html/nsHTMLEditRules.cpp
@@ -6311,16 +6311,20 @@ nsHTMLEditRules::ReturnInHeader(nsISelec
     NS_ENSURE_SUCCESS(res, res);
     // layout tells the caret to blink in a weird place
     // if we don't place a break after the header.
     nsCOMPtr<nsIDOMNode> sibling;
     res = mHTMLEditor->GetNextHTMLSibling(headerParent, offset+1, address_of(sibling));
     NS_ENSURE_SUCCESS(res, res);
     if (!sibling || !nsTextEditUtils::IsBreak(sibling))
     {
+      res = ClearCachedStyles();
+      NS_ENSURE_SUCCESS(res, res);
+      mHTMLEditor->mTypeInState->ClearAllProps();
+
       // create a paragraph
       NS_NAMED_LITERAL_STRING(pType, "p");
       nsCOMPtr<nsIDOMNode> pNode;
       res = mHTMLEditor->CreateNode(pType, headerParent, offset+1, getter_AddRefs(pNode));
       NS_ENSURE_SUCCESS(res, res);
 
       // append a <br> to it
       nsCOMPtr<nsIDOMNode> brNode;
@@ -6557,16 +6561,20 @@ nsHTMLEditRules::ReturnInListItem(nsISel
       res = aSelection->Collapse(aListItem,0);
     }
     else
     {
       // otherwise kill this listitem
       res = mHTMLEditor->DeleteNode(aListItem);
       NS_ENSURE_SUCCESS(res, res);
       
+      res = ClearCachedStyles();
+      NS_ENSURE_SUCCESS(res, res);
+      mHTMLEditor->mTypeInState->ClearAllProps();
+
       // time to insert a paragraph
       NS_NAMED_LITERAL_STRING(pType, "p");
       nsCOMPtr<nsIDOMNode> pNode;
       res = mHTMLEditor->CreateNode(pType, listparent, offset+1, getter_AddRefs(pNode));
       NS_ENSURE_SUCCESS(res, res);
 
       // append a <br> to it
       nsCOMPtr<nsIDOMNode> brNode;
--- a/editor/libeditor/html/tests/Makefile.in
+++ b/editor/libeditor/html/tests/Makefile.in
@@ -79,16 +79,18 @@ MOCHITEST_FILES = \
 		test_root_element_replacement.html \
 		test_bug738366.html \
 		test_bug757371.html \
 		test_bug767684.html \
 		test_bug780035.html \
 		test_bug787432.html \
 		test_bug790475.html \
 		test_bug796839.html \
+		test_bug832025.html \
+		test_bug832025_2.html \
 		test_spellcheck_pref.html \
 		$(NULL)
 
 _DATA_FILES = \
 		data/cfhtml-chromium.txt \
 		data/cfhtml-firefox.txt \
 		data/cfhtml-ie.txt \
 		data/cfhtml-ooo.txt \
new file mode 100644
--- /dev/null
+++ b/editor/libeditor/html/tests/test_bug832025.html
@@ -0,0 +1,42 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=832025
+-->
+<head>
+  <title>Test for Bug 832025</title>
+  <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=832025">Mozilla Bug 832025</a>
+<div id="test" contenteditable="true">header1</div>
+<script type="application/javascript">
+
+/**
+ * Test for Bug 832025
+ *
+ */
+
+document.execCommand("stylewithcss", false, "true");
+var test = document.getElementById("test");
+test.focus();
+
+// place caret at end of editable area
+var sel = getSelection();
+sel.collapse(test, test.childNodes.length);
+
+// make it a H1
+document.execCommand("heading", false, "H1");
+// simulate a CR key
+sendKey("return");
+// insert some text
+document.execCommand("insertText", false, "abc");
+
+is(test.innerHTML == '<h1>header1</h1><p>abc<br></p>',
+   true, "A paragraph automatically created after a CR at the end of an H1 should not be bold");
+
+</script>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/editor/libeditor/html/tests/test_bug832025_2.html
@@ -0,0 +1,42 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=832025
+-->
+<head>
+  <title>Test for Bug 832025</title>
+  <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=832025">Mozilla Bug 832025</a>
+<div id="test" contenteditable="true"><ul><li>listitem <strong id="s">strong</strong></li></ul></div>
+<script type="application/javascript">
+
+/**
+ * Second Test for Bug 832025
+ *
+ */
+
+document.execCommand("stylewithcss", false, "true");
+var test = document.getElementById("test");
+var s = document.getElementById("s");
+test.focus();
+
+// place caret at end of editable area
+var sel = getSelection();
+sel.collapse(s, s.childNodes.length);
+
+// simulate two CR keys
+sendKey("return");
+sendKey("return");
+// insert some text
+document.execCommand("insertText", false, "abc");
+
+is(test.innerHTML == '<ul><li>listitem <strong id="s">strong</strong></li></ul><p>abc<br></p>',
+   true, "A paragraph automatically created after two CRs at the end of a bold listitem should not be bold");
+
+</script>
+</body>
+</html>