X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FTexRow.cpp;h=21be0b8e30f69f1eed42ea4273cad5d514746918;hb=57b69a5efddf9f3c148007322f00dad6c253a2ed;hp=fe2f694e279f9d2c30d2d7a9030c99f5924308e0;hpb=73d3816e0f2083a2dc53d744f32d206a153556be;p=lyx.git diff --git a/src/TexRow.cpp b/src/TexRow.cpp index fe2f694e27..21be0b8e30 100644 --- a/src/TexRow.cpp +++ b/src/TexRow.cpp @@ -35,12 +35,21 @@ bool TexRow::RowEntryList::addEntry(RowEntry const & entry) if (!entry.is_math) { if (text_entry_ < size()) return false; - else + else { text_entry_ = size(); + push_back(RowEntry(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; } @@ -60,8 +69,16 @@ TexRow::RowEntry TexRow::RowEntryList::entry() const } +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) @@ -130,9 +147,17 @@ bool TexRow::start(int id, int pos) } -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)); } @@ -161,18 +186,33 @@ void TexRow::finalize() } +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); } @@ -267,8 +307,8 @@ public: { return row_it_ == row_end_; } - - + + bool operator==(RowListIterator const & a) const { return row_it_ == a.row_it_ && ((atEnd() && a.atEnd()) || it_ == a.it_); @@ -353,7 +393,7 @@ std::pair TexRow::rowFromDocIterator(DocIterator const & dit) const 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()) @@ -406,8 +446,13 @@ std::pair TexRow::rowFromCursor(Cursor const & cur) const std::pair 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 end_rows = rowFromDocIterator(end); return std::make_pair(std::min(beg_rows.first, end_rows.first), std::max(beg_rows.second, end_rows.second)); @@ -433,7 +478,7 @@ docstring TexRow::asString(RowEntry const & entry) ///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::const_iterator it = rowlist_.begin(); @@ -447,7 +492,7 @@ void TexRow::prepend(docstring_list & tex) const 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]; } } @@ -460,7 +505,7 @@ LyXErr & operator<<(LyXErr & l, TexRow & texrow) 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;