From 1407f0e9c548fd245a3cfd1520068839b9d4ed34 Mon Sep 17 00:00:00 2001 From: Mirko Brodesser Date: Fri, 30 Apr 2021 07:43:28 +0000 Subject: [PATCH] Bug 1708422: part 1) Factor `mozInlineSpellChecker::AddRangesForMisspelledWords` out. r=smaug Abstracts details away. Differential Revision: https://phabricator.services.mozilla.com/D113779 --- .../spellcheck/src/mozInlineSpellChecker.cpp | 32 +++++++++++++--------- extensions/spellcheck/src/mozInlineSpellChecker.h | 8 ++++++ 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/extensions/spellcheck/src/mozInlineSpellChecker.cpp b/extensions/spellcheck/src/mozInlineSpellChecker.cpp index e19b05a7a153..f5418a498951 100644 --- a/extensions/spellcheck/src/mozInlineSpellChecker.cpp +++ b/extensions/spellcheck/src/mozInlineSpellChecker.cpp @@ -1516,19 +1516,8 @@ void mozInlineSpellChecker::CheckCurrentWordsNoSuggest( return; } - for (size_t i = 0; i < aIsMisspelled.Length(); i++) { - if (!aIsMisspelled[i]) { - continue; - } - - RefPtr wordRange = - mozInlineSpellWordUtil::MakeRange(ranges[i]); - // If we somehow can't make a range for this word, just ignore - // it. - if (wordRange) { - self->AddRange(spellCheckerSelection, wordRange); - } - } + self->AddRangesForMisspelledWords(ranges, aIsMisspelled, + *spellCheckerSelection); }, [self, token](nsresult aRv) { if (!self->mTextEditor || self->mTextEditor->Destroyed()) { @@ -1692,6 +1681,23 @@ nsresult mozInlineSpellChecker::RemoveRange(Selection* aSpellCheckSelection, return rv.StealNSResult(); } +void mozInlineSpellChecker::AddRangesForMisspelledWords( + const nsTArray& aRanges, + const nsTArray& aIsMisspelled, Selection& aSpellCheckerSelection) { + for (size_t i = 0; i < aIsMisspelled.Length(); i++) { + if (!aIsMisspelled[i]) { + continue; + } + + RefPtr wordRange = mozInlineSpellWordUtil::MakeRange(aRanges[i]); + // If we somehow can't make a range for this word, just ignore + // it. + if (wordRange) { + AddRange(&aSpellCheckerSelection, wordRange); + } + } +} + // mozInlineSpellChecker::AddRange // // For performance reasons, we have an upper bound on the number of word diff --git a/extensions/spellcheck/src/mozInlineSpellChecker.h b/extensions/spellcheck/src/mozInlineSpellChecker.h index 4c05e54b12d2..9a4eb67191ec 100644 --- a/extensions/spellcheck/src/mozInlineSpellChecker.h +++ b/extensions/spellcheck/src/mozInlineSpellChecker.h @@ -258,6 +258,7 @@ class mozInlineSpellChecker final : public nsIInlineSpellChecker, // (https://bugzilla.mozilla.org/show_bug.cgi?id=1620540). MOZ_CAN_RUN_SCRIPT_BOUNDARY nsresult RemoveRange(mozilla::dom::Selection* aSpellCheckSelection, nsRange* aRange); + MOZ_CAN_RUN_SCRIPT_BOUNDARY nsresult AddRange(mozilla::dom::Selection* aSpellCheckSelection, nsRange* aRange); bool IsSpellCheckSelectionFull() const { @@ -295,6 +296,13 @@ class mozInlineSpellChecker final : public nsIInlineSpellChecker, protected: virtual ~mozInlineSpellChecker(); + // Adds the ranges corresponding to the misspelled words as long as + // aSpellCheckerSelection isn't full. + MOZ_CAN_RUN_SCRIPT_BOUNDARY void AddRangesForMisspelledWords( + const nsTArray& aRanges, + const nsTArray& aIsMisspelled, + mozilla::dom::Selection& aSpellCheckerSelection); + // called when async nsIEditorSpellCheck methods complete nsresult EditorSpellCheckInited(); nsresult CurrentDictionaryUpdated(); -- 2.11.4.GIT