]> git.lyx.org Git - features.git/commitdiff
Make CursorData::checkNewWordPosition() more robust
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 31 Jan 2018 15:26:45 +0000 (16:26 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 31 Jan 2018 15:26:45 +0000 (16:26 +0100)
Before accessing things like new_word_.lastpos(), it is better to make
sure that new_word_ points to something that exists. Therefore, the
call to fixIfBroken() is moved in first position.

Other changes: inTexted() is replaced by a more general test that
current inset has not changed; test idx() in addition to pit().

src/Cursor.cpp

index 3f5bff854cfabe9c5506ca6637658748f8168539..83b7378785ce980cb94894b11fd7037cbc96f78d 100644 (file)
@@ -457,34 +457,32 @@ void CursorData::checkNewWordPosition()
 {
        if (!lyxrc.spellcheck_continuously || new_word_.empty())
                return ;
-       if (!inTexted())
-               clearNewWordPosition();
-       else {
-               // forget the position of the current new word if
-               // 1) the paragraph changes or
-               // 2) the count of nested insets changes or
-               // 3) the cursor pos is out of paragraph bound
-               if (pit() != new_word_.pit() ||
-                       depth() != new_word_.depth() ||
-                       new_word_.pos() > new_word_.lastpos()) {
-                       clearNewWordPosition();
-               } else if (new_word_.fixIfBroken())
-                       // 4) or the remembered position was "broken"
+       // forget the position of the current new word if
+       // 1) or the remembered position was "broken"
+       // 2) or the count of nested insets changed
+       // 3) the top-level inset is not the same anymore
+       // 4) the cell index changed
+       // 5) or the paragraph changed
+       // 6) or the cursor pos is out of paragraph bound
+       if (new_word_.fixIfBroken()
+           || depth() != new_word_.depth()
+           || &inset() != &new_word_.inset()
+           || pit() != new_word_.pit()
+           || idx() != new_word_.idx()
+           || new_word_.pos() > new_word_.lastpos())
                        clearNewWordPosition();
-               else {
-                       FontSpan nw = locateWord(WHOLE_WORD);
-                       if (!nw.empty()) {
-                               FontSpan ow = new_word_.locateWord(WHOLE_WORD);
-                               if (nw.intersect(ow).empty())
-                                       clearNewWordPosition();
-                               else
-                                       LYXERR(Debug::DEBUG, "new word: "
-                                                  << " par: " << pit()
-                                                  << " pos: " << nw.first << ".." << nw.last);
-                       } else {
+       else {
+               FontSpan nw = locateWord(WHOLE_WORD);
+               if (!nw.empty()) {
+                       FontSpan ow = new_word_.locateWord(WHOLE_WORD);
+                       if (nw.intersect(ow).empty())
                                clearNewWordPosition();
-                       }
-               }
+                       else
+                               LYXERR(Debug::DEBUG, "new word: "
+                                          << " par: " << pit()
+                                          << " pos: " << nw.first << ".." << nw.last);
+               } else
+                       clearNewWordPosition();
        }
 }