From 168b96deba7fee8a6e3ede740afeae953f22d1ae Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Sun, 6 Apr 2014 17:56:08 +0300 Subject: [PATCH] Bug 923376 - Spellcheck all appended nodes, not just the first; r=ehsan --- editor/libeditor/html/nsHTMLEditor.cpp | 23 ++++++++++++-- editor/libeditor/html/nsHTMLEditor.h | 5 ++- editor/libeditor/html/tests/923376-ref.html | 13 ++++++++ editor/libeditor/html/tests/923376.html | 16 ++++++++++ editor/libeditor/html/tests/mochitest.ini | 3 ++ .../libeditor/html/tests/test_bug923376.html | 31 +++++++++++++++++++ 6 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 editor/libeditor/html/tests/923376-ref.html create mode 100644 editor/libeditor/html/tests/923376.html create mode 100644 editor/libeditor/html/tests/test_bug923376.html diff --git a/editor/libeditor/html/nsHTMLEditor.cpp b/editor/libeditor/html/nsHTMLEditor.cpp index 895a8e86cae..4962f77607f 100644 --- a/editor/libeditor/html/nsHTMLEditor.cpp +++ b/editor/libeditor/html/nsHTMLEditor.cpp @@ -3227,12 +3227,22 @@ nsHTMLEditor::ContentAppended(nsIDocument *aDocument, nsIContent* aContainer, nsIContent* aFirstNewContent, int32_t aIndexInContainer) { - ContentInserted(aDocument, aContainer, aFirstNewContent, aIndexInContainer); + DoContentInserted(aDocument, aContainer, aFirstNewContent, aIndexInContainer, + eAppended); } void nsHTMLEditor::ContentInserted(nsIDocument *aDocument, nsIContent* aContainer, nsIContent* aChild, int32_t aIndexInContainer) +{ + DoContentInserted(aDocument, aContainer, aChild, aIndexInContainer, + eInserted); +} + +void +nsHTMLEditor::DoContentInserted(nsIDocument* aDocument, nsIContent* aContainer, + nsIContent* aChild, int32_t aIndexInContainer, + InsertedOrAppended aInsertedOrAppended) { if (!aChild) { return; @@ -3257,8 +3267,17 @@ nsHTMLEditor::ContentInserted(nsIDocument *aDocument, nsIContent* aContainer, // Update spellcheck for only the newly-inserted node (bug 743819) if (mInlineSpellChecker) { nsRefPtr range = new nsRange(aChild); + int32_t endIndex = aIndexInContainer + 1; + if (aInsertedOrAppended == eAppended) { + // Count all the appended nodes + nsIContent* sibling = aChild->GetNextSibling(); + while (sibling) { + endIndex++; + sibling = sibling->GetNextSibling(); + } + } nsresult res = range->Set(aContainer, aIndexInContainer, - aContainer, aIndexInContainer + 1); + aContainer, endIndex); if (NS_SUCCEEDED(res)) { mInlineSpellChecker->SpellCheckRange(range); } diff --git a/editor/libeditor/html/nsHTMLEditor.h b/editor/libeditor/html/nsHTMLEditor.h index b52ce78cca3..918f67fbbcb 100644 --- a/editor/libeditor/html/nsHTMLEditor.h +++ b/editor/libeditor/html/nsHTMLEditor.h @@ -950,7 +950,10 @@ private: nsIAtom* aProperty, const nsAString* aAttribute, const nsAString* aValue); - + typedef enum { eInserted, eAppended } InsertedOrAppended; + void DoContentInserted(nsIDocument* aDocument, nsIContent* aContainer, + nsIContent* aChild, int32_t aIndexInContainer, + InsertedOrAppended aInsertedOrAppended); }; #endif //nsHTMLEditor_h__ diff --git a/editor/libeditor/html/tests/923376-ref.html b/editor/libeditor/html/tests/923376-ref.html new file mode 100644 index 00000000000..5955241cb8d --- /dev/null +++ b/editor/libeditor/html/tests/923376-ref.html @@ -0,0 +1,13 @@ + +
something missspelled
something elsed#
+ + diff --git a/editor/libeditor/html/tests/923376.html b/editor/libeditor/html/tests/923376.html new file mode 100644 index 00000000000..b99a816695e --- /dev/null +++ b/editor/libeditor/html/tests/923376.html @@ -0,0 +1,16 @@ + +
+ + diff --git a/editor/libeditor/html/tests/mochitest.ini b/editor/libeditor/html/tests/mochitest.ini index b8ed9aab3a9..f235e2ffc16 100644 --- a/editor/libeditor/html/tests/mochitest.ini +++ b/editor/libeditor/html/tests/mochitest.ini @@ -10,6 +10,8 @@ support-files = file_bug674770-1.html file_select_all_without_body.html green.png + 923376.html + 923376-ref.html [test_CF_HTML_clipboard.html] [test_bug200416.html] @@ -94,6 +96,7 @@ skip-if = toolkit == 'android' || e10s [test_bug796839.html] [test_bug832025.html] [test_bug857487.html] +[test_bug923376.html] [test_bug966155.html] skip-if = os != "win" [test_bug966552.html] diff --git a/editor/libeditor/html/tests/test_bug923376.html b/editor/libeditor/html/tests/test_bug923376.html new file mode 100644 index 00000000000..7bc0d5f68e6 --- /dev/null +++ b/editor/libeditor/html/tests/test_bug923376.html @@ -0,0 +1,31 @@ + + +Test for Bug 923376 + + + +Mozilla Bug 923376 + + +