- // Search for a separator where the row can be broken.
- while (cit != beg && boost::prior(cit)->type != SEPARATOR && new_end > keep) {
+ if (last_sep != end) {
+ // We have found a suitable separator. This is the
+ // common case.
+ end_ = last_sep->endpos;
+ dim_.wid = last_width;
+ elements_.erase(last_sep, end);
+ return;
+ }
+
+ if (cit == end) {
+ // This should not happen since the row is too long.
+ LYXERR0("Something is wrong cannot shorten row: " << *this);
+ return;
+ }
+
+ if (cit != beg && cit->type == VIRTUAL) {
+ // It is not possible to separate a virtual element from the
+ // previous one.