Skip to content

Commit

Permalink
Disabled text checking while any key is auto-repeating.
Browse files Browse the repository at this point in the history
  • Loading branch information
23rd committed Oct 23, 2020
1 parent 1ce9c43 commit 053e44a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
29 changes: 25 additions & 4 deletions spellcheck/spelling_highlighter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,6 @@ SpellingHighlighter::SpellingHighlighter(
Platform::Spellchecker::Init();
#endif // !Q_OS_WIN

_textEdit->installEventFilter(this);
_textEdit->viewport()->installEventFilter(this);

_cachedRanges = MisspelledWords();

// Use the patched SpellCheckUnderline style.
Expand Down Expand Up @@ -203,6 +200,13 @@ SpellingHighlighter::SpellingHighlighter(
enabled
) | rpl::start_with_next([=](bool value) {
setEnabled(value);
if (_enabled) {
_textEdit->installEventFilter(this);
_textEdit->viewport()->installEventFilter(this);
} else {
_textEdit->removeEventFilter(this);
_textEdit->viewport()->removeEventFilter(this);
}
}, _lifetime);

Spellchecker::SupportedScriptsChanged(
Expand Down Expand Up @@ -347,7 +351,9 @@ void SpellingHighlighter::contentsChange(int pos, int removed, int added) {
_lastPosition--;
_addedSymbols++;
}

if (_isLastKeyRepeat) {
return;
}
checkChangedText();
}
}
Expand Down Expand Up @@ -634,6 +640,21 @@ bool SpellingHighlighter::eventFilter(QObject *o, QEvent *e) {
if (_addedSymbols + _removedSymbols + _lastPosition) {
checkCurrentText();
}
} else if ((o == _textEdit) && k->isAutoRepeat()) {
_isLastKeyRepeat = true;
}
} else if (_isLastKeyRepeat && (o == _textEdit)) {
if (e->type() == QEvent::FocusOut) {
_isLastKeyRepeat = false;
if (_addedSymbols + _removedSymbols + _lastPosition) {
checkCurrentText();
}
} else if (e->type() == QEvent::KeyRelease) {
const auto k = static_cast<QKeyEvent*>(e);
if (!k->isAutoRepeat()) {
_isLastKeyRepeat = false;
_coldSpellcheckingTimer.callOnce(kColdSpellcheckingTimeout);
}
}
} else if ((o == _textEdit->viewport())
&& (e->type() == QEvent::MouseButtonPress)) {
Expand Down
2 changes: 2 additions & 0 deletions spellcheck/spelling_highlighter.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ class SpellingHighlighter final : public QSyntaxHighlighter {
int _lastPosition = 0;
bool _enabled = true;

bool _isLastKeyRepeat = false;

base::Timer _coldSpellcheckingTimer;

not_null<Ui::InputField*> _field;
Expand Down

0 comments on commit 053e44a

Please sign in to comment.