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

View file

@ -35,6 +35,8 @@
#include <QStringList> #include <QStringList>
#include <QTimer> #include <QTimer>
#include "app/App.hpp" #include "app/App.hpp"
#include "components/core/CoreManager.hpp"
#include "components/settings/SettingsModel.hpp"
#ifdef __linux__ #ifdef __linux__
#include <thread> #include <thread>
@ -57,7 +59,10 @@ public:
~SpellChecker(); ~SpellChecker();
// Common // 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 void setTextDocument(QQuickTextDocument *textDocument);
Q_INVOKABLE int wordPosition(int x, int y); Q_INVOKABLE int wordPosition(int x, int y);
Q_INVOKABLE bool isWordAtPositionValid(int cursorPosition); Q_INVOKABLE bool isWordAtPositionValid(int cursorPosition);

View file

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

View file

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

View file

@ -1566,6 +1566,14 @@ void SettingsModel::setSavedScreenshotsFolder (const QString &folder) {
emit savedScreenshotsFolderChanged(cleanedFolder); 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) { static inline string getLegacySavedCallsFolder (const shared_ptr<linphone::Config> &config) {

View file

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