mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-23 10:18:50 +00:00
Fix part of bug http://www.lyx.org/trac/ticket/2566
We use Inset::producesOutput to skip things like notes and inactive branches. * buffer_funcs.cpp (countWords): align code style with countChars; skip insets for which producesOutput() is false. (countChars): honor Inset::producesOutput. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30242 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
8a421dcd37
commit
01b290e2dd
@ -168,42 +168,68 @@ Buffer * newUnnamedFile(string const & templatename, FileName const & path)
|
|||||||
return newFile(filename.absFilename(), templatename, false);
|
return newFile(filename.absFilename(), templatename, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* FIXME : merge with countChars. The structures of the two functions
|
||||||
|
* 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)
|
||||||
|
*/
|
||||||
int countWords(DocIterator const & from, DocIterator const & to)
|
int countWords(DocIterator const & from, DocIterator const & to)
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
bool inword = false;
|
bool inword = false;
|
||||||
for (DocIterator dit = from ; dit != to ; dit.forwardPos()) {
|
for (DocIterator dit = from ; dit != to ; ) {
|
||||||
// FIXME: use Paragraph::isWordSeparator
|
if (!dit.inTexted()) {
|
||||||
|
dit.forwardPos();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Paragraph const & par = dit.paragraph();
|
||||||
|
pos_type const pos = dit.pos();
|
||||||
|
|
||||||
// Copied and adapted from isWordSeparator() in Paragraph
|
// Copied and adapted from isWordSeparator() in Paragraph
|
||||||
if (dit.inTexted()
|
if (pos != dit.lastpos() && !par.isDeleted(pos)) {
|
||||||
&& dit.pos() != dit.lastpos()
|
Inset const * ins = par.getInset(pos);
|
||||||
&& !dit.paragraph().isWordSeparator(dit.pos())
|
if (ins && !ins->producesOutput()) {
|
||||||
&& !dit.paragraph().isDeleted(dit.pos())) {
|
//skip this inset
|
||||||
if (!inword) {
|
++dit.top().pos();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (par.isWordSeparator(pos))
|
||||||
|
inword = false;
|
||||||
|
else if (!inword) {
|
||||||
++count;
|
++count;
|
||||||
inword = true;
|
inword = true;
|
||||||
}
|
}
|
||||||
} else if (inword)
|
}
|
||||||
inword = false;
|
dit.forwardPos();
|
||||||
}
|
}
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int countChars(DocIterator const & from, DocIterator const & to, bool with_blanks)
|
int countChars(DocIterator const & from, DocIterator const & to,
|
||||||
|
bool with_blanks)
|
||||||
{
|
{
|
||||||
int chars = 0;
|
int chars = 0;
|
||||||
int blanks = 0;
|
int blanks = 0;
|
||||||
for (DocIterator dit = from ; dit != to ; dit.forwardPos()) {
|
for (DocIterator dit = from ; dit != to ; ) {
|
||||||
|
if (!dit.inTexted()) {
|
||||||
|
dit.forwardPos();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!dit.inTexted()) continue;
|
|
||||||
Paragraph const & par = dit.paragraph();
|
Paragraph const & par = dit.paragraph();
|
||||||
pos_type const pos = dit.pos();
|
pos_type const pos = dit.pos();
|
||||||
|
|
||||||
if (pos != dit.lastpos() && !par.isDeleted(pos)) {
|
if (pos != dit.lastpos() && !par.isDeleted(pos)) {
|
||||||
if (Inset const * ins = par.getInset(pos)) {
|
if (Inset const * ins = par.getInset(pos)) {
|
||||||
|
if (!ins->producesOutput()) {
|
||||||
|
//skip this inset
|
||||||
|
++dit.top().pos();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (ins->isLetter())
|
if (ins->isLetter())
|
||||||
++chars;
|
++chars;
|
||||||
else if (with_blanks && ins->isSpace())
|
else if (with_blanks && ins->isSpace())
|
||||||
@ -216,6 +242,7 @@ int countChars(DocIterator const & from, DocIterator const & to, bool with_blank
|
|||||||
++blanks;
|
++blanks;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
dit.forwardPos();
|
||||||
}
|
}
|
||||||
|
|
||||||
return chars + blanks;
|
return chars + blanks;
|
||||||
|
Loading…
Reference in New Issue
Block a user