Spell checker fixes & improvements

This commit is contained in:
Christophe Deschamps 2023-11-07 10:09:17 +00:00 committed by Julien Wadel
parent 2839e892e8
commit f61c11759f
8 changed files with 29 additions and 9 deletions

2
external/ispell vendored

@ -1 +1 @@
Subproject commit 061c7e52b507f146396c3b08f289c88ca598fc2f
Subproject commit b4ac0ab9772904732e98d5d402b553556bd4ce78

View file

@ -23,8 +23,7 @@
#include <QTimer>
#include <QAbstractTextDocumentLayout>
#include <QTextEdit>
#include "components/core/CoreManager.hpp"
#include "components/settings/SettingsModel.hpp"
#ifdef WIN32
#include <spellcheck.h>
@ -54,7 +53,8 @@ SpellChecker::SpellChecker(QObject *parent) : QSyntaxHighlighter(parent) {
connect(graceTimer, SIGNAL(timeout()), SLOT(highlightAfterGracePeriod()));
mAvailable = false;
setLanguage();
if (CoreManager::getInstance()->getSettingsModel()->getSpellCheckerEnabled())
setLanguage();
}
SpellChecker::~SpellChecker () {

View file

@ -35,6 +35,8 @@
#include <QStringList>
#include <QTimer>
#include "app/App.hpp"
#include "components/core/CoreManager.hpp"
#include "components/settings/SettingsModel.hpp"
#ifdef __linux__
#include <thread>
@ -57,7 +59,10 @@ public:
~SpellChecker();
// Common
static QString currentLanguage() { return App::getInstance()->getLocale().name();}
static QString currentLanguage() {
QString overrideLocale = CoreManager::getInstance()->getSettingsModel()->getSpellCheckerOverrideLocale();
return overrideLocale.isEmpty() ? App::getInstance()->getLocale().name() : overrideLocale;
}
Q_INVOKABLE void setTextDocument(QQuickTextDocument *textDocument);
Q_INVOKABLE int wordPosition(int x, int y);
Q_INVOKABLE bool isWordAtPositionValid(int cursorPosition);

View file

@ -19,8 +19,8 @@
*/
#import "SpellChecker.hpp"
#import <libispell.h>
#include "SpellChecker.hpp"
#include <libispell.h>
#include "app/paths/Paths.hpp"
#include <unistd.h>
#include <cstdio>

View file

@ -28,12 +28,15 @@ void SpellChecker::setLanguage() {
if ([spellChecker setLanguage:locale.toNSString()]) {
[spellChecker updatePanels];
qDebug() << LOG_TAG << "Macos native spell checker Language set to " << locale;
mAvailable = true;
} else {
qWarning() << LOG_TAG << "Macos native spell checker unable to set language to " << locale;
}
}
bool SpellChecker::isValid(QString word) {
if (!mAvailable)
return true;
NSSpellChecker *spellChecker = [NSSpellChecker sharedSpellChecker];
QString locale = SpellChecker::currentLanguage();
bool isValid = [spellChecker checkSpellingOfString:word.toNSString() startingAt:0 language:locale.toNSString() wrap:NO inSpellDocumentWithTag:0 wordCount:nullptr].length == 0;

View file

@ -58,12 +58,13 @@ void SpellChecker::setLanguage() {
qWarning() << LOG_TAG << "Windows native spell checker unable to create spell checker";
return;
}
qWarning() << LOG_TAG << "Windows native spell checker created for locale" << locale;
qDebug() << LOG_TAG << "Windows native spell checker created for locale" << locale;
mAvailable = true;
}
bool SpellChecker::isValid(QString word) {
if (mNativeSpellChecker == nullptr)
if (!mAvailable)
return true;
wchar_t *text = reinterpret_cast<wchar_t *>(word.data());
IEnumSpellingError* enumSpellingError = nullptr;

View file

@ -1566,6 +1566,14 @@ void SettingsModel::setSavedScreenshotsFolder (const QString &folder) {
emit savedScreenshotsFolderChanged(cleanedFolder);
}
QString SettingsModel::getSpellCheckerOverrideLocale() const{
return Utils::coreStringToAppString(mConfig->getString(UiSection, "spell_checker_override_locale", ""));
}
bool SettingsModel::getSpellCheckerEnabled() const{
return mConfig->getBool(UiSection, "spell_checker_enabled", true);
}
// -----------------------------------------------------------------------------
static inline string getLegacySavedCallsFolder (const shared_ptr<linphone::Config> &config) {

View file

@ -589,6 +589,9 @@ public:
int getEmojiFontSize() const;
void setEmojiFontSize(const int& size);
QString getSpellCheckerOverrideLocale() const;
bool getSpellCheckerEnabled() const;
QString getSavedScreenshotsFolder () const;
void setSavedScreenshotsFolder (const QString &folder);