]> git.lyx.org Git - lyx.git/blobdiff - src/buffer_funcs.cpp
* InsetSpecialChar.cpp:
[lyx.git] / src / buffer_funcs.cpp
index ed699084f2851a8f877bde38285605e65df87c1e..c3e277c433a1b6299243c2c3540a0c5df264187b 100644 (file)
@@ -184,7 +184,8 @@ int countWords(DocIterator const & from, DocIterator const & to)
 {
        int count = 0;
        bool inword = false;
-       for (DocIterator dit = from ; dit != to ; ) {
+       
+       for (DocIterator dit = from ; dit != to && !dit.empty(); ) {
                if (!dit.inTexted()) {
                        dit.forwardPos();
                        continue;
@@ -192,13 +193,17 @@ int countWords(DocIterator const & from, DocIterator const & to)
                
                Paragraph const & par = dit.paragraph();
                pos_type const pos = dit.pos();
-               
+
                // Copied and adapted from isWordSeparator() in Paragraph
-               if (pos != dit.lastpos() && !par.isDeleted(pos)) {
+               if (pos == dit.lastpos()) {
+                       inword = false;
+               } else if (!par.isDeleted(pos)) {
                        Inset const * ins = par.getInset(pos);
                        if (ins && !ins->producesOutput()) {
                                //skip this inset
                                ++dit.top().pos();
+                               if (dit >= to)
+                                       break;
                                continue;
                        }
                        if (par.isWordSeparator(pos))