]> git.lyx.org Git - features.git/commitdiff
Fix a crash when spellchecking when a Math inset is the last inset in the document...
authorVincent van Ravesteijn <vfr@lyx.org>
Sat, 12 Dec 2009 02:56:06 +0000 (02:56 +0000)
committerVincent van Ravesteijn <vfr@lyx.org>
Sat, 12 Dec 2009 02:56:06 +0000 (02:56 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@32489 a592a061-630c-0410-9148-cb99ea01b6c8

src/Buffer.cpp

index e827bc9780118e1a57a62af5e32918f6a0325d44..1a37dcc2102d32f85b69a8cfafd3b4ebb9c1d450 100644 (file)
@@ -3735,15 +3735,26 @@ int Buffer::spellCheck(DocIterator & from, DocIterator & to,
        DocIterator const end = doc_iterator_end(this);
        for (; from != end; from.forwardPos()) {
                // We are only interested in text so remove the math CursorSlice.
-               while (from.inMathed())
-                       from.forwardInset();
+               while (from.inMathed()) {
+                       from.pop_back();
+                       from.pos()++;
+               }
+               // If from is at the end of the document (which is possible
+               // when leaving the mathed) LyX will crash later.
+               if (from == end)
+                       break;
                to = from;
                if (from.paragraph().spellCheck(from.pos(), to.pos(), wl, suggestions)) {
                        word_lang = wl;
                        break;
                }
-               from = to;
-               ++progress;
+
+               // Do not increase progress when from == to, otherwise the word
+               // count will be wrong.
+               if (from != to) {
+                       from = to;
+                       ++progress;
+               }
        }
        return progress;
 }