diff --git a/src/buffer_funcs.cpp b/src/buffer_funcs.cpp index c3e277c433..ff4512b5c6 100644 --- a/src/buffer_funcs.cpp +++ b/src/buffer_funcs.cpp @@ -179,13 +179,19 @@ Buffer * newUnnamedFile(FileName const & path, string const & prefix, * are similar but, unfortunately, they seem to have a different * notion of what to count. Since nobody ever complained about that, * this proves (again) that any number beats no number ! (JMarc) + * We have two use cases: + * 1. Count the words of the given range for document statistics + * - ignore inset content without output. (skipNoOutput == true) + * 2. Count the words to present a progress bar for the spell checker + * - has to count whole content. (skipNoOutput == false) */ -int countWords(DocIterator const & from, DocIterator const & to) +int countWords(DocIterator const & from, DocIterator const & to, + bool skipNoOutput) { int count = 0; bool inword = false; - for (DocIterator dit = from ; dit != to && !dit.empty(); ) { + for (DocIterator dit = from ; dit != to && !dit.atEnd(); ) { if (!dit.inTexted()) { dit.forwardPos(); continue; @@ -199,10 +205,11 @@ int countWords(DocIterator const & from, DocIterator const & to) inword = false; } else if (!par.isDeleted(pos)) { Inset const * ins = par.getInset(pos); - if (ins && !ins->producesOutput()) { - //skip this inset + if (ins && skipNoOutput && !ins->producesOutput()) { + // skip this inset ++dit.top().pos(); - if (dit >= to) + // stop if end of range was skipped + if (!to.atEnd() && dit >= to) break; continue; } diff --git a/src/buffer_funcs.h b/src/buffer_funcs.h index f7dd645df3..97449cc4b1 100644 --- a/src/buffer_funcs.h +++ b/src/buffer_funcs.h @@ -47,7 +47,8 @@ Buffer * newUnnamedFile(support::FileName const & path, Buffer * loadIfNeeded(support::FileName const & fname); /// Count the number of words in the text between these two iterators -int countWords(DocIterator const & from, DocIterator const & to); +int countWords(DocIterator const & from, DocIterator const & to, + bool skipNoOutput = true); /// Count the number of chars in the text between these two iterators int countChars(DocIterator const & from, DocIterator const & to, bool with_blanks); diff --git a/src/frontends/qt4/GuiSpellchecker.cpp b/src/frontends/qt4/GuiSpellchecker.cpp index 9e9da468dc..4ee9953f02 100644 --- a/src/frontends/qt4/GuiSpellchecker.cpp +++ b/src/frontends/qt4/GuiSpellchecker.cpp @@ -270,8 +270,8 @@ bool GuiSpellchecker::initialiseParams(string const &) DocIterator const begin = doc_iterator_begin(&buffer()); Cursor const & cur = bufferview()->cursor(); - d->progress_ = countWords(begin, cur); - d->total_ = d->progress_ + countWords(cur, doc_iterator_end(&buffer())); + d->progress_ = countWords(begin, cur, false); + d->total_ = d->progress_ + countWords(cur, doc_iterator_end(&buffer()), false); d->count_ = 0; return true; }