]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/controllers/ControlSpellchecker.C
fix crash due to invalidated iterator
[lyx.git] / src / frontends / controllers / ControlSpellchecker.C
index 161fba9d271a7936cbda711e2ff5d0f5fc08ca1d..7e0c88d281d247a926c71ca8c48e638e65ac2387 100644 (file)
@@ -54,7 +54,7 @@ namespace frontend {
 
 
 ControlSpellchecker::ControlSpellchecker(Dialog & parent)
-       : Dialog::Controller(parent),
+       : Dialog::Controller(parent), exitEarly_(false),
          oldval_(0), newvalue_(0), count_(0)
 {}
 
@@ -108,8 +108,9 @@ bool ControlSpellchecker::initialiseParams(std::string const &)
        bool const success = speller_->error().empty();
 
        if (!success) {
-               Alert::error(_("The spell-checker could not be started"),
-                            speller_->error());
+               Alert::error(_("Spellchecker error"),
+                            _("The spellchecker could not be started\n")
+                            + speller_->error());
                speller_.reset(0);
        }
 
@@ -165,7 +166,7 @@ WordLangTuple nextWord(DocIterator & cur, ptrdiff_t & progress,
                        }
                } else { // !isLetter(cur)
                        if (inword)
-                               if (!ignoreword)
+                               if (!word.empty() && !ignoreword)
                                        return WordLangTuple(word, lang_code);
                                else
                                        inword = false;
@@ -184,11 +185,14 @@ WordLangTuple nextWord(DocIterator & cur, ptrdiff_t & progress,
 
 void ControlSpellchecker::check()
 {
-       lyxerr[Debug::GUI] << "spell check a word" << endl;
+       lyxerr[Debug::GUI] << "Check the spelling of a word" << endl;
 
        SpellBase::Result res = SpellBase::OK;
 
        DocIterator cur = kernel().bufferview()->cursor();
+       while (cur && cur.pos() && isLetter(cur)) {
+               cur.backwardPos();
+       }
 
        ptrdiff_t start = 0, total = 0;
        DocIterator it = DocIterator(kernel().buffer().inset());
@@ -198,10 +202,8 @@ void ControlSpellchecker::check()
        for (total = start; it; it.forwardPos())
                ++total;
 
-       for (; cur && cur.pos() && isLetter(cur); cur.forwardPos())
-               ++start;
-
        BufferParams & bufferparams = kernel().buffer().params();
+       exitEarly_ = false;
 
        while (res == SpellBase::OK || res == SpellBase::IGNORED_WORD) {
                word_ = nextWord(cur, start, bufferparams);
@@ -209,6 +211,7 @@ void ControlSpellchecker::check()
                // end of document
                if (getWord().empty()) {
                        showSummary();
+                       exitEarly_ = true;
                        return;
                }
 
@@ -257,14 +260,17 @@ bool ControlSpellchecker::checkAlive()
        if (speller_->alive() && speller_->error().empty())
                return true;
 
-       string message = speller_->error();
-       if (message.empty())
-               message = _("The spell-checker has died for some reason.\n"
-                        "Maybe it has been killed.");
+       string message;
+       if (speller_->error().empty())
+               message = _("The spellchecker has died for some reason.\n"
+                           "Maybe it has been killed.");
+       else
+               message = _("The spellchecker has failed.\n") 
+                       + speller_->error();
 
        dialog().CancelButton();
 
-       Alert::error(_("The spell-checker has failed"), message);
+       Alert::error(_("The spellchecker has failed"), message);
        return false;
 }
 
@@ -283,7 +289,7 @@ void ControlSpellchecker::showSummary()
                message = _("One word checked.");
 
        dialog().CancelButton();
-       Alert::information(_("Spell-checking is complete"), message);
+       Alert::information(_("Spelling check completed"), message);
 }