From fa1c9b453d5309dc9f25cec9f12d90ff9328a48b Mon Sep 17 00:00:00 2001 From: Olli Pettay Date: Fri, 1 Dec 2023 16:39:03 +0000 Subject: [PATCH] Bug 1837268, update inline spellchecker when text data is modified, a=RyanVM Using the test for bug 1602526 as the basis for the new test but tweaking it by adding the event listener used in the first testcase of the bug. Original Revision: https://phabricator.services.mozilla.com/D184987 Differential Revision: https://phabricator.services.mozilla.com/D195233 --- editor/libeditor/HTMLEditor.cpp | 18 +++++ editor/libeditor/HTMLEditor.h | 1 + editor/spellchecker/tests/mochitest.ini | 1 + .../spellchecker/tests/test_bug1837268.html | 79 +++++++++++++++++++ 4 files changed, 99 insertions(+) create mode 100644 editor/spellchecker/tests/test_bug1837268.html diff --git a/editor/libeditor/HTMLEditor.cpp b/editor/libeditor/HTMLEditor.cpp index 0f0a22805d12..474ce8b841fc 100644 --- a/editor/libeditor/HTMLEditor.cpp +++ b/editor/libeditor/HTMLEditor.cpp @@ -4551,6 +4551,24 @@ MOZ_CAN_RUN_SCRIPT_BOUNDARY void HTMLEditor::ContentRemoved( } } +MOZ_CAN_RUN_SCRIPT_BOUNDARY void HTMLEditor::CharacterDataChanged( + nsIContent* aContent, const CharacterDataChangeInfo& aInfo) { + if (!mInlineSpellChecker || !aContent->IsEditable() || + !IsInObservedSubtree(aContent) || + GetTopLevelEditSubAction() != EditSubAction::eNone) { + return; + } + + nsIContent* parent = aContent->GetParent(); + if (!parent || !parent->InclusiveDescendantMayNeedSpellchecking(this)) { + return; + } + + RefPtr range = nsRange::Create(aContent); + range->SelectNodesInContainer(parent, aContent, aContent); + DebugOnly rvIgnored = mInlineSpellChecker->SpellCheckRange(range); +} + nsresult HTMLEditor::SelectEntireDocument() { MOZ_ASSERT(IsEditActionDataAvailable()); diff --git a/editor/libeditor/HTMLEditor.h b/editor/libeditor/HTMLEditor.h index a0ff6bf5f8bc..fabdf1d9e4e2 100644 --- a/editor/libeditor/HTMLEditor.h +++ b/editor/libeditor/HTMLEditor.h @@ -102,6 +102,7 @@ class HTMLEditor final : public EditorBase, NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED + NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED // nsIHTMLEditor methods NS_DECL_NSIHTMLEDITOR diff --git a/editor/spellchecker/tests/mochitest.ini b/editor/spellchecker/tests/mochitest.ini index f728ecf82077..6d3c53d71b10 100644 --- a/editor/spellchecker/tests/mochitest.ini +++ b/editor/spellchecker/tests/mochitest.ini @@ -40,6 +40,7 @@ skip-if = true [test_bug1602526.html] [test_bug1761273.html] [test_bug1773802.html] +[test_bug1837268.html] [test_bug366682.html] [test_bug432225.html] [test_bug484181.html] diff --git a/editor/spellchecker/tests/test_bug1837268.html b/editor/spellchecker/tests/test_bug1837268.html new file mode 100644 index 000000000000..1467a328b5df --- /dev/null +++ b/editor/spellchecker/tests/test_bug1837268.html @@ -0,0 +1,79 @@ + + + + Mozilla bug 1837268 + + + + + + +Mozilla Bug 1837268 +

+ + +
aabbcc
+ + + +