if (!entry.is_math) {
if (text_entry_ < size())
return false;
- else
+ else {
text_entry_ = size();
+ push_back(entry);
+ return true;
+ }
}
+ forceAddEntry(entry);
+ return true;
+}
+
+
+void TexRow::RowEntryList::forceAddEntry(RowEntry const & entry)
+{
if (size() == 0 || !(operator[](size() - 1) == entry))
push_back(RowEntry(entry));
- return true;
}
}
+void TexRow::RowEntryList::append(RowEntryList const & row)
+{
+ if (text_entry_ >= size())
+ text_entry_ = row.text_entry_ + size();
+ insert(end(), row.begin(), row.end());
+}
+
+
TexRow::TextEntry const TexRow::text_none = { -1, 0 };
-TexRow::RowEntry const TexRow::row_none = { false, TexRow::text_none };
+TexRow::RowEntry const TexRow::row_none = { false, { TexRow::text_none } };
bool TexRow::isNone(TextEntry const & t)
}
-bool TexRow::startMath(uid_type id, idx_type cell)
+void TexRow::forceStart(int id, int pos)
{
- return start(mathEntry(id,cell));
+ if (!enabled_)
+ return;
+ return current_row_.forceAddEntry(textEntry(id,pos));
+}
+
+
+void TexRow::startMath(uid_type id, idx_type cell)
+{
+ start(mathEntry(id,cell));
}
}
+void TexRow::append(TexRow const & texrow)
+{
+ if (!enabled_ || !texrow.enabled_)
+ return;
+ RowList::const_iterator it = texrow.rowlist_.begin();
+ RowList::const_iterator const end = texrow.rowlist_.end();
+ if (it == end) {
+ current_row_.append(texrow.current_row_);
+ } else {
+ current_row_.append(*it++);
+ rowlist_.push_back(current_row_);
+ rowlist_.insert(rowlist_.end(), it, end);
+ current_row_ = texrow.current_row_;
+ }
+}
+
+
+
bool TexRow::getIdFromRow(int row, int & id, int & pos) const
{
TextEntry t = text_none;
- bool ret = false;
if (row <= int(rowlist_.size()))
while (row > 0 && isNone(t = rowlist_[row - 1].getTextEntry()))
--row;
- if (row > 0)
- ret = true;
id = t.id;
pos = t.pos;
- return ret;
+ return !isNone(t);
}
{
return row_it_ == row_end_;
}
-
-
+
+
bool operator==(RowListIterator const & a) const
{
return row_it_ == a.row_it_ && ((atEnd() && a.atEnd()) || it_ == a.it_);
end_offset = 1;
break;
case -1: {
- // ...or it is the row preceding the first that matches pos+1
+ // ...or it is the row preceding the first that matches pos+1
if (!end_is_next) {
end_is_next = true;
if (it.row() != best_end_entry.row())
std::pair<int,int> beg_rows = rowFromDocIterator(beg);
if (cur.selection()) {
DocIterator end = cur.selectionEnd();
- if (!cur.selIsMultiCell())
- end.top().backwardPos();
+ if (!cur.selIsMultiCell()
+ // backwardPos asserts without the following test, IMO it's not my
+ // duty to check this.
+ && (end.top().pit() != 0
+ || end.top().idx() != 0
+ || end.top().pos() != 0))
+ end.top().backwardPos();
std::pair<int,int> end_rows = rowFromDocIterator(end);
return std::make_pair(std::min(beg_rows.first, end_rows.first),
std::max(beg_rows.second, end_rows.second));
///prepends the texrow to the source given by tex, for debugging purpose
void TexRow::prepend(docstring_list & tex) const
{
- int const prefix_length = 25;
+ size_type const prefix_length = 25;
if (tex.size() < rowlist_.size())
tex.resize(rowlist_.size());
std::vector<RowEntryList>::const_iterator it = rowlist_.begin();
entry += asString(*it2);
if (entry.length() < prefix_length)
entry = entry + docstring(prefix_length - entry.length(), L' ');
- int i = it - beg;
+ ptrdiff_t i = it - beg;
tex[i] = entry + " " + tex[i];
}
}
for (int i = 0; i < texrow.rows(); i++) {
int id,pos;
if (texrow.getIdFromRow(i+1,id,pos) && id>0)
- l << i+1 << ":" << id << ":" << pos << "\n";
+ l << i+1 << ":" << id << ":" << pos << "\n";
}
}
return l;