X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FTexRow.cpp;h=780cd52af07f7ec5702a3ffca107d99f6ec7ed51;hb=b64d17e9dcaeb84a94095622c93a051e4d93eab7;hp=6d88ba614140050f78702b4ecf0144e1e16c24b2;hpb=2bf1c09376de37a3d66b79ca5f4304f29d5b4d06;p=lyx.git diff --git a/src/TexRow.cpp b/src/TexRow.cpp index 6d88ba6141..780cd52af0 100644 --- a/src/TexRow.cpp +++ b/src/TexRow.cpp @@ -4,7 +4,7 @@ * Licence details can be found in the file COPYING. * * \author Matthias Ettrich - * \author Lars Gullik Bjønnes + * \author Lars Gullik Bjønnes * \author John Levon * * Full author contact details are available in file CREDITS. @@ -32,8 +32,12 @@ void TexRow::reset() void TexRow::start(int id, int pos) { + if (started) + return; + lastid = id; lastpos = pos; + started = true; } @@ -42,8 +46,15 @@ void TexRow::newline() int const id = lastid; RowList::value_type tmp(id, lastpos); rowlist.push_back(tmp); + started = false; } +void TexRow::newlines(int num_lines) +{ + for (int i = 0; i < num_lines; ++i) { + newline(); + } +} bool TexRow::getIdFromRow(int row, int & id, int & pos) const { @@ -61,22 +72,24 @@ bool TexRow::getIdFromRow(int row, int & id, int & pos) const int TexRow::getRowFromIdPos(int id, int pos) const { - int bestrow = 0; bool foundid = false; - // this loop finds the last *nonempty* row whith the same id + // this loop finds the last *nonempty* row with the same id // and position <= pos - for (unsigned r = 0, n = rowlist.size(); r != n; ++r) { - if (rowlist[r].id() == id && rowlist[r].pos() <= pos) { + RowList::const_iterator bestrow = rowlist.begin(); + RowList::const_iterator it = rowlist.begin(); + RowList::const_iterator const end = rowlist.end(); + for (; it != end; ++it) { + if (it->id() == id && it->pos() <= pos) { foundid = true; - if (rowlist[bestrow].id() != id || rowlist[r].pos() > rowlist[bestrow].pos()) - bestrow = r; + if (bestrow->id() != id || it->pos() > bestrow->pos()) + bestrow = it; } else if (foundid) break; } if (!foundid) return rowlist.size(); - return bestrow; + return distance(rowlist.begin(), bestrow) + 1; }