#include "output_latex.h"
#include "paragraph_funcs.h"
#include "ParagraphParameters.h"
+#include "SpellChecker.h"
#include "sgml.h"
#include "TextClass.h"
#include "TexRow.h"
#include "Text.h"
#include "VSpace.h"
+#include "WordLangTuple.h"
#include "WordList.h"
#include "frontends/alert.h"
if (Inset const * inset = getInset(pos))
return inset->isLetter();
char_type const c = d->text_[pos];
- return isLetterChar(c) || isDigit(c);
+ // We want to pass the ' and escape chars to the spellchecker
+ static docstring const quote = from_utf8(lyxrc.spellchecker_esc_chars + '\'');
+ return (isLetterChar(c) || isDigit(c) || contains(quote, c))
+ && (!d->inset_owner_ || d->inset_owner_->allowSpellCheck())
+ && pos != size()
+ && !isDeleted(pos);
}
}
-void Paragraph::collectWords(CursorSlice const & sl)
+void Paragraph::collectWords()
{
- // find new words
- bool inword = false;
+ SpellChecker * speller = theSpellChecker();
//lyxerr << "Words: ";
pos_type n = size();
for (pos_type pos = 0; pos < n; ++pos) {
- if (isDeleted(pos))
+ if (!isLetter(pos))
continue;
- if (!isLetter(pos)) {
- inword = false;
- continue;
- }
- if (inword)
- continue;
-
- inword = true;
pos_type from = pos;
locateWord(from, pos, WHOLE_WORD);
- if (pos - from < 6)
+ if (!lyxrc.spellcheck_continuously && pos - from < 6)
continue;
+
docstring word = asString(from, pos, false);
- d->words_.insert(word);
+ if (pos - from >= 6)
+ d->words_.insert(word);
+
+ if (!lyxrc.spellcheck_continuously || !speller)
+ continue;
+
+ string lang_code = lyxrc.spellchecker_use_alt_lang
+ ? lyxrc.spellchecker_alt_lang
+ : getFontSettings(d->inset_owner_->buffer().params(), from).language()->code();
+ WordLangTuple wl(word, lang_code);
+ SpellChecker::Result res = speller->check(wl);
+ // ... just ignore any error that the spellchecker reports.
+ if (!speller->error().empty())
+ continue;
+ bool const misspelled = res != SpellChecker::OK
+ && res != SpellChecker::IGNORED_WORD;
+ d->fontlist_.setMisspelled(from, pos, misspelled);
+
//lyxerr << word << " ";
}
//lyxerr << std::endl;
}
-void Paragraph::updateWords(CursorSlice const & sl)
+void Paragraph::updateWords()
{
- LASSERT(&sl.paragraph() == this, /**/);
deregisterWords();
- collectWords(sl);
+ collectWords();
registerWords();
}