]> git.lyx.org Git - lyx.git/blobdiff - src/Paragraph.cpp
Patch from Peter.
[lyx.git] / src / Paragraph.cpp
index 3371afaf3e63609ce06b41a6e03380a8dd2c4139..93727a3ede05f76a720251330e8fa68e912a120c 100644 (file)
@@ -2352,7 +2352,12 @@ bool Paragraph::isLetter(pos_type pos) const
        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);
 }
 
 
@@ -2905,15 +2910,13 @@ void Paragraph::locateWord(pos_type & from, pos_type & to,
 }
 
 
-void Paragraph::collectWords(CursorSlice const & sl)
+void Paragraph::collectWords()
 {
        SpellChecker * speller = theSpellChecker();
 
        //lyxerr << "Words: ";
        pos_type n = size();
        for (pos_type pos = 0; pos < n; ++pos) {
-               if (isDeleted(pos))
-                       continue;
                if (!isLetter(pos))
                        continue;
                pos_type from = pos;
@@ -2955,12 +2958,39 @@ void Paragraph::registerWords()
 }
 
 
-void Paragraph::updateWords(CursorSlice const & sl)
+void Paragraph::updateWords()
 {
-       LASSERT(&sl.paragraph() == this, /**/);
        deregisterWords();
-       collectWords(sl);
+       collectWords();
        registerWords();
 }
 
+
+bool Paragraph::isMisspelled(pos_type pos) const
+{
+       SpellChecker * speller = theSpellChecker();
+       pos_type from = pos;
+       pos_type to = pos;
+       locateWord(from, to, WHOLE_WORD);
+       docstring word = asString(from, to, false);
+       if (!speller)
+               return false;
+               
+       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())
+               return false;
+
+       bool const misspelled = res != SpellChecker::OK
+               && res != SpellChecker::IGNORED_WORD;
+       if (lyxrc.spellcheck_continuously)
+               d->fontlist_.setMisspelled(from, pos, misspelled);
+       return misspelled;
+}
+
+
 } // namespace lyx