Bug 1708422: part 1) Factor `mozInlineSpellChecker::AddRangesForMisspelledWords` out. r=smaug

Abstracts details away.

Differential Revision: https://phabricator.services.mozilla.com/D113779
This commit is contained in:
Mirko Brodesser 2021-04-30 07:43:28 +00:00
Родитель 25be52e55f
Коммит 1407f0e9c5
2 изменённых файлов: 27 добавлений и 13 удалений

Просмотреть файл

@ -1516,19 +1516,8 @@ void mozInlineSpellChecker::CheckCurrentWordsNoSuggest(
return;
}
for (size_t i = 0; i < aIsMisspelled.Length(); i++) {
if (!aIsMisspelled[i]) {
continue;
}
RefPtr<nsRange> 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<NodeOffsetRange>& aRanges,
const nsTArray<bool>& aIsMisspelled, Selection& aSpellCheckerSelection) {
for (size_t i = 0; i < aIsMisspelled.Length(); i++) {
if (!aIsMisspelled[i]) {
continue;
}
RefPtr<nsRange> 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

Просмотреть файл

@ -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<NodeOffsetRange>& aRanges,
const nsTArray<bool>& aIsMisspelled,
mozilla::dom::Selection& aSpellCheckerSelection);
// called when async nsIEditorSpellCheck methods complete
nsresult EditorSpellCheckInited();
nsresult CurrentDictionaryUpdated();