Skip to content

Commit

Permalink
Fixed spellchecking for Windows.
Browse files Browse the repository at this point in the history
Added a new Init static method in the Platform::Spellchecker namespace.
  • Loading branch information
23rd committed Dec 10, 2019
1 parent f5e7b4e commit 1cd02ea
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
3 changes: 3 additions & 0 deletions spellcheck/platform/linux/spellcheck_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ bool EnchantSpellChecker::isWordInDictionary(const QString &word) {

} // namespace

void Init() {
}

bool IsAvailable() {
return EnchantSpellChecker::instance()->isAvailable();
}
Expand Down
3 changes: 3 additions & 0 deletions spellcheck/platform/mac/spellcheck_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ inline auto SystemLanguages() {

namespace Platform::Spellchecker {

void Init() {
}

bool IsAvailable() {
return true;
}
Expand Down
1 change: 1 addition & 0 deletions spellcheck/platform/platform_spellcheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ constexpr auto kMaxSuggestions = 5;
[[nodiscard]] bool CheckSpelling(const QString &wordToCheck);
[[nodiscard]] bool IsWordInDictionary(const QString &wordToCheck);

void Init();
void KnownLanguages(std::vector<QString> *langCodes);
void FillSuggestionList(
const QString &wrongWord,
Expand Down
15 changes: 12 additions & 3 deletions spellcheck/platform/win/spellcheck_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ void WindowsSpellChecker::checkSpellingText(

void WindowsSpellChecker::addWord(LPCWSTR word) {
for (const auto &[_, spellchecker] : _spellcheckerMap) {
spellchecker->Add(Q2WString(word));
spellchecker->Add(word);
}
}

Expand All @@ -233,14 +233,14 @@ void WindowsSpellChecker::removeWord(LPCWSTR word) {
ComPtr<ISpellChecker2> spellchecker2;
spellchecker->QueryInterface(IID_PPV_ARGS(&spellchecker2));
if (spellchecker2) {
spellchecker2->Remove(Q2WString(word));
spellchecker2->Remove(word);
}
}
}

void WindowsSpellChecker::ignoreWord(LPCWSTR word) {
for (const auto &[_, spellchecker] : _spellcheckerMap) {
spellchecker->Ignore(Q2WString(word));
spellchecker->Ignore(word);
}
}

Expand All @@ -257,6 +257,15 @@ std::unique_ptr<WindowsSpellChecker>& SharedSpellChecker() {

} // namespace

// TODO: Add a better work with the Threading Models.
// All COM objects should be created asynchronously
// if we want to work with them asynchronously.
// Some calls can be made in the main thread before spellchecking
// (e.g. KnownLanguages), so we have to init it asynchronously first.
void Init() {
crl::async(SharedSpellChecker);
}

bool IsAvailable() {
return IsWindows8OrGreater();
}
Expand Down
3 changes: 3 additions & 0 deletions spellcheck/spelling_highlighter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ SpellingHighlighter::SpellingHighlighter(
, _coldSpellcheckingTimer([=] { checkChangedText(); })
, _field(field)
, _textEdit(field->rawTextEdit()) {
#ifdef Q_OS_WIN
Platform::Spellchecker::Init();
#endif

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

0 comments on commit 1cd02ea

Please sign in to comment.