Skip to content

Commit

Permalink
Slightly refactored code.
Browse files Browse the repository at this point in the history
  • Loading branch information
23rd committed Oct 22, 2020
1 parent 58263c0 commit 1ce9c43
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions spellcheck/platform/linux/spellcheck_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ bool EnchantSpellChecker::checkSpelling(const QString &word) {
// Hspell is the spell checker that only checks words in Hebrew.
// It returns 'true' for any non-Hebrew word,
// so we should skip Hspell if a word is not in Hebrew.
if (ranges::find_if(_hspells, [&](auto &v) {
if (ranges::any_of(_hspells, [&](auto &v) {
return v == validator.get();
}) != _hspells.end()) {
})) {
return false;
}
if (validator->get_lang().find("uk") == 0) {
Expand Down
4 changes: 2 additions & 2 deletions spellcheck/platform/mac/spellcheck_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void Init() {

bool CheckSpelling(const QString &wordToCheck) {
const auto wordLength = wordToCheck.length();
NSArray<NSTextCheckingResult *> *spellRanges =
NSArray<NSTextCheckingResult*> *spellRanges =
[SharedSpellChecker()
checkString:Q2NSString(std::move(wordToCheck))
range:NSMakeRange(0, wordLength)
Expand All @@ -80,7 +80,7 @@ void CheckSpellingText(
// Probably never gonna be defined.
#ifdef SPELLCHECKER_MAC_AUTO_CHECK_TEXT

NSArray<NSTextCheckingResult *> *spellRanges =
NSArray<NSTextCheckingResult*> *spellRanges =
[SharedSpellChecker()
checkString:Q2NSString(text)
range:NSMakeRange(0, text.length())
Expand Down
6 changes: 3 additions & 3 deletions spellcheck/spellcheck_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ QChar::Script LocaleToScriptCode(const QString &locale) {

QChar::Script WordScript(const QStringRef &word) {
// Find the first letter.
const auto firstLetter = ranges::find_if(word, [&](QChar c) {
const auto firstLetter = ranges::find_if(word, [](QChar c) {
return c.isLetter();
});
return firstLetter == word.end()
Expand All @@ -237,12 +237,12 @@ bool IsWordSkippable(const QStringRef &word, bool checkSupportedScripts) {
&& !ranges::contains(SupportedScripts, wordScript)) {
return true;
}
return ranges::find_if(word, [&](QChar c) {
return ranges::any_of(word, [&](QChar c) {
return (c.script() != wordScript)
&& !IsAcuteAccentChar(c)
&& (c.unicode() != '\'') // Patched Qt to make it a non-separator.
&& (c.unicode() != '_'); // This is not a word separator.
}) != word.end();
});
}

void UpdateSupportedScripts(std::vector<QString> languages) {
Expand Down
22 changes: 11 additions & 11 deletions spellcheck/spelling_highlighter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,9 @@ inline bool IsTagUnspellcheckable(const QString &tag) {
if (tag.isEmpty()) {
return false;
}
const auto isCommonFormatting = ranges::find_if(
kUnspellcheckableTags, [&](const auto *t) {
return t == tag;
}) != end(kUnspellcheckableTags);
const auto isCommonFormatting = ranges::any_of(
kUnspellcheckableTags,
[&](const auto *t) { return t == tag; });

if (isCommonFormatting) {
return true;
Expand Down Expand Up @@ -390,12 +389,13 @@ void SpellingHighlighter::checkChangedText() {
const auto beginNewSelection = wordUnderCursor.first;
const auto endNewSelection = EndOfWord(lastWordNewSelection);

auto callback = [=](MisspelledWords &&r) {
ranges::insert(_cachedRanges, wordInCacheIt(), std::move(r));
};
invokeCheckText(
beginNewSelection,
endNewSelection - beginNewSelection,
[=](const MisspelledWords &r) {
ranges::insert(_cachedRanges, wordInCacheIt(), std::move(r));
});
std::move(callback));
return;
}

Expand Down Expand Up @@ -436,15 +436,15 @@ void SpellingHighlighter::checkCurrentText() {
_cachedRanges.clear();
return;
}
invokeCheckText(0, size(), [&](const MisspelledWords &ranges) {
invokeCheckText(0, size(), [&](MisspelledWords &&ranges) {
_cachedRanges = std::move(ranges);
});
}

void SpellingHighlighter::invokeCheckText(
int textPosition,
int textLength,
Fn<void(const MisspelledWords &ranges)> callback) {
Fn<void(MisspelledWords &&ranges)> callback) {
if (!_enabled) {
return;
}
Expand Down Expand Up @@ -608,7 +608,7 @@ bool SpellingHighlighter::eventFilter(QObject *o, QEvent *e) {
return false;
}
if (e->type() == QEvent::ContextMenu) {
const auto c = static_cast<QContextMenuEvent *>(e);
const auto c = static_cast<QContextMenuEvent*>(e);
const auto menu = _textEdit->createStandardContextMenu();
if (!menu || !c) {
return false;
Expand All @@ -628,7 +628,7 @@ bool SpellingHighlighter::eventFilter(QObject *o, QEvent *e) {
c->globalPos());
return true;
} else if (e->type() == QEvent::KeyPress) {
const auto k = static_cast<QKeyEvent *>(e);
const auto k = static_cast<QKeyEvent*>(e);

if (ranges::contains(kKeysToCheck, k->key())) {
if (_addedSymbols + _removedSymbols + _lastPosition) {
Expand Down
2 changes: 1 addition & 1 deletion spellcheck/spelling_highlighter.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class SpellingHighlighter final : public QSyntaxHighlighter {
void invokeCheckText(
int textPosition,
int textLength,
Fn<void(const MisspelledWords &ranges)> callback);
Fn<void(MisspelledWords &&ranges)> callback);

void checkChangedText();
void checkSingleWord(const MisspelledWord &singleWord);
Expand Down

0 comments on commit 1ce9c43

Please sign in to comment.