mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-23 10:18:50 +00:00
732212f233
of the first call of TexRow::start(), rather than the last before a newline. This is what was causing some recent grief (bug #7325, for example). git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37894 a592a061-630c-0410-9148-cb99ea01b6c8
97 lines
1.6 KiB
C++
97 lines
1.6 KiB
C++
/**
|
|
* \file TexRow.cpp
|
|
* This file is part of LyX, the document processor.
|
|
* Licence details can be found in the file COPYING.
|
|
*
|
|
* \author Matthias Ettrich
|
|
* \author Lars Gullik Bjønnes
|
|
* \author John Levon
|
|
*
|
|
* Full author contact details are available in file CREDITS.
|
|
*/
|
|
|
|
#include <config.h>
|
|
|
|
#include "TexRow.h"
|
|
|
|
#include "support/debug.h"
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
void TexRow::reset()
|
|
{
|
|
rowlist.clear();
|
|
lastid = -1;
|
|
lastpos = -1;
|
|
}
|
|
|
|
|
|
void TexRow::start(int id, int pos)
|
|
{
|
|
if (started)
|
|
return;
|
|
|
|
lastid = id;
|
|
lastpos = pos;
|
|
started = true;
|
|
}
|
|
|
|
|
|
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
|
|
{
|
|
if (row <= 0 || row > int(rowlist.size())) {
|
|
id = -1;
|
|
pos = 0;
|
|
return false;
|
|
}
|
|
|
|
id = rowlist[row - 1].id();
|
|
pos = rowlist[row - 1].pos();
|
|
return true;
|
|
}
|
|
|
|
|
|
int TexRow::getRowFromIdPos(int id, int pos) const
|
|
{
|
|
bool foundid = false;
|
|
|
|
// this loop finds the last *nonempty* row with the same id
|
|
// and position <= 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 (bestrow->id() != id || it->pos() > bestrow->pos())
|
|
bestrow = it;
|
|
} else if (foundid)
|
|
break;
|
|
}
|
|
if (!foundid)
|
|
return rowlist.size();
|
|
return distance(rowlist.begin(), bestrow) + 1;
|
|
}
|
|
|
|
|
|
} // namespace lyx
|