diff --git a/src/spellcheck/ontheflycheck.h b/src/spellcheck/ontheflycheck.h --- a/src/spellcheck/ontheflycheck.h +++ b/src/spellcheck/ontheflycheck.h @@ -119,6 +119,8 @@ protected Q_SLOTS: void performSpellCheck(); + void addToDictionary(const QString &word); + void addToSession(const QString &word); void misspelling(const QString &word, int start); void spellCheckDone(); diff --git a/src/spellcheck/ontheflycheck.cpp b/src/spellcheck/ontheflycheck.cpp --- a/src/spellcheck/ontheflycheck.cpp +++ b/src/spellcheck/ontheflycheck.cpp @@ -401,11 +401,32 @@ this, SLOT(misspelling(QString,int))); connect(m_backgroundChecker, SIGNAL(done()), this, SLOT(spellCheckDone())); + + KateSpellCheckManager *m_spellCheckManager = KTextEditor::EditorPrivate::self()->spellCheckManager(); + connect(m_spellCheckManager, &KateSpellCheckManager::wordAddedToDictionary, + this, &KateOnTheFlyChecker::addToDictionary); + connect(m_spellCheckManager, &KateSpellCheckManager::wordIgnored, + this, &KateOnTheFlyChecker::addToSession); } m_backgroundChecker->setSpeller(m_speller); m_backgroundChecker->setText(text); // don't call 'start()' after this! } +void KateOnTheFlyChecker::addToDictionary(const QString &word) +{ + if (m_backgroundChecker) { + m_backgroundChecker->addWordToPersonal(word); + } +} + +void KateOnTheFlyChecker::addToSession(const QString &word) +{ + if (m_backgroundChecker) { + m_backgroundChecker->addWordToSession(word); + } +} + + void KateOnTheFlyChecker::removeRangeFromEverything(KTextEditor::MovingRange *movingRange) { Q_ASSERT(m_document == movingRange->document()); diff --git a/src/spellcheck/spellcheck.h b/src/spellcheck/spellcheck.h --- a/src/spellcheck/spellcheck.h +++ b/src/spellcheck/spellcheck.h @@ -52,6 +52,14 @@ **/ static QList rangeDifference(const KTextEditor::Range &r1, const KTextEditor::Range &r2); +Q_SIGNALS: + /** + * These signals are used to propagate the dictionary changes to the + * BackgroundChecker instance in other components (e.g. onTheFlyChecker). + */ + void wordAddedToDictionary(const QString &word); + void wordIgnored(const QString &word); + public: QList > spellCheckLanguageRanges(KTextEditor::DocumentPrivate *doc, const KTextEditor::Range &range); diff --git a/src/spellcheck/spellcheck.cpp b/src/spellcheck/spellcheck.cpp --- a/src/spellcheck/spellcheck.cpp +++ b/src/spellcheck/spellcheck.cpp @@ -56,13 +56,15 @@ Sonnet::Speller speller; speller.setLanguage(dictionary); speller.addToSession(word); + emit wordIgnored(word); } void KateSpellCheckManager::addToDictionary(const QString &word, const QString &dictionary) { Sonnet::Speller speller; speller.setLanguage(dictionary); speller.addToPersonal(word); + emit wordAddedToDictionary(word); } QList KateSpellCheckManager::rangeDifference(const KTextEditor::Range &r1,