Added application name as exception word for spell checker.

This commit is contained in:
23rd 2020-03-16 17:11:44 +03:00 committed by John Preston
parent 759fa14759
commit 15db48b0cc
1 changed files with 41 additions and 11 deletions

View File

@ -31,6 +31,11 @@ using namespace Storage::CloudBlob;
constexpr auto kDictExtensions = { "dic", "aff" };
constexpr auto kExceptions = {
AppFile,
"\xd0\xa2\xd0\xb5\xd0\xbb\xd0\xb5\xd0\xb3\xd1\x80\xd0\xb0\xd0\xbc"_cs,
};
// 31 - QLocale::English, 91 - QLocale::Portuguese.
constexpr auto kLangsForLWC = { 31, 91 };
// 225 - QLocale::UnitesStates, 30 - QLocale::Brazil.
@ -167,6 +172,19 @@ void DownloadDictionaryInBackground(
BackgroundLoaderChanged.fire_copy(id);
}
void AddExceptions() {
const auto exceptions = ranges::view::all(
kExceptions
) | ranges::views::transform([](const auto &word) {
return word.utf16();
}) | ranges::views::filter([](const auto &word) {
return !(Platform::Spellchecker::IsWordInDictionary(word)
|| Spellchecker::IsWordSkippable(&word));
}) | ranges::to_vector;
ranges::for_each(exceptions, Platform::Spellchecker::AddWord);
}
} // namespace
DictLoaderPtr GlobalLoader() {
@ -358,17 +376,34 @@ void Start(not_null<Main::Session*> session) {
} });
const auto settings = &session->settings();
const auto guard = gsl::finally([=]{
if (settings->spellcheckerEnabled()) {
Platform::Spellchecker::UpdateLanguages(
settings->dictionariesEnabled());
}
const auto onEnabled = [=](auto enabled) {
Platform::Spellchecker::UpdateLanguages(
enabled
? settings->dictionariesEnabled()
: std::vector<int>());
};
const auto guard = gsl::finally([=] {
onEnabled(settings->spellcheckerEnabled());
});
if (Platform::Spellchecker::IsSystemSpellchecker()) {
const auto scriptsLifetime =
session->lifetime().make_state<rpl::lifetime>();
Spellchecker::SupportedScriptsChanged(
) | rpl::start_with_next([=] {
AddExceptions();
scriptsLifetime->destroy();
}, *scriptsLifetime);
return;
}
Spellchecker::SupportedScriptsChanged(
) | rpl::start_with_next(AddExceptions, session->lifetime());
Spellchecker::SetWorkingDirPath(DictionariesPath());
settings->dictionariesEnabledChanges(
@ -377,12 +412,7 @@ void Start(not_null<Main::Session*> session) {
}, session->lifetime());
settings->spellcheckerEnabledChanges(
) | rpl::start_with_next([=](auto enabled) {
Platform::Spellchecker::UpdateLanguages(
enabled
? settings->dictionariesEnabled()
: std::vector<int>());
}, session->lifetime());
) | rpl::start_with_next(onEnabled, session->lifetime());
const auto method = QGuiApplication::inputMethod();