]> git.lyx.org Git - lyx.git/commitdiff
#9514 improved document iterator for correct check of speller disabled state
authorStephan Witt <switt@lyx.org>
Fri, 8 May 2015 09:13:32 +0000 (11:13 +0200)
committerStephan Witt <switt@lyx.org>
Fri, 8 May 2015 09:13:51 +0000 (11:13 +0200)
src/Buffer.cpp
src/DocIterator.cpp
src/DocIterator.h
src/RowPainter.cpp

index fb3602691d1d477c2d06ed28b6902d8a11afd5a9..e12d83076ab65b6112d5cdb3d4fd2c15ee228f1c 100644 (file)
@@ -4808,14 +4808,13 @@ int Buffer::spellCheck(DocIterator & from, DocIterator & to,
        DocIterator const end = to_end ? doc_iterator_end(this) : to;
        // OK, we start from here.
        for (; from != end; from.forwardPos()) {
-               // We are only interested in text so remove the math CursorSlice.
-               // The same is done for insets with disabled spell check.
-               while (from.inMathed() || !from.inset().allowSpellCheck()) {
+               // This skips all insets with spell check disabled.
+               while (!from.allowSpellCheck()) {
                        from.pop_back();
                        from.pos()++;
                }
                // If from is at the end of the document (which is possible
-               // when "from" was manipulated) LyX will crash later otherwise.
+               // when "from" was changed above) LyX will crash later otherwise.
                if (from.atEnd() || (!to_end && from >= end))
                        break;
                to = from;
index 4dbd2614de2c0045e11cd77ad35ae9ea8b7eb154..9783db14a10d9562df0444c144ced76037b4f87b 100644 (file)
@@ -482,6 +482,19 @@ bool DocIterator::hasPart(DocIterator const & it) const
 }
 
 
+bool DocIterator::allowSpellCheck() const
+{
+       /// spell check is disabled if the iterator position
+       /// is inside of an inset which disables the spell checker
+       size_t const n = depth();
+       for (size_t i = 0; i < n; ++i) {
+               if (!slices_[i].inset_->allowSpellCheck())
+                       return false;
+       }
+       return true;
+}
+
+
 void DocIterator::updateInsets(Inset * inset)
 {
        // this function re-creates the cache of inset pointers.
index 6a86e41d44b0a7f8e9115d6ca88a9b144626fa89..74dd47438ff85609ba5b8917bcadcd20c3a44c17 100644 (file)
@@ -75,6 +75,9 @@ public:
        /// is this the last possible position?
        bool atLastPos() const { return pit() == lastpit() && pos() == lastpos(); }
 
+       /// checks the cursor slices for disabled spell checker insets
+       bool allowSpellCheck() const;
+
        //
        // access to slice at tip
        //
index fbe35792a201b0462095de6cbbbfaa9f5dc94b3e..d556cfa07e20893170bfa35fcd9e81974ce8636d 100644 (file)
@@ -330,8 +330,8 @@ void RowPainter::paintFromPos(pos_type & vpos, bool changed)
                                --cpos;
                        new_word = par_.isSameSpellRange(pos, cpos) ;
                }
-               if (!new_word)
-                       paintMisspelledMark(orig_x, changed);
+               if (!new_word && pi_.do_spellcheck)
+                       paintMisspelledMark(orig_x, changed, font);
        }
 }