+ if (before)
+ start = const_cast<LyXParagraph*>(before->next());
+ else
+ start = FirstParagraph();
+ if (behind)
+ end = const_cast<LyXParagraph*>(behind->previous());
+ else {
+ end = FirstParagraph();
+ while (end->next())
+ end = end->next();
+ }
+ if (start && end && (start != end->next()) &&
+ ((before != behind) || (!before && !behind))) {
+ tmppar = start;
+ tmppar2 = tmppar->Clone();
+ tmppar2->id(tmppar->id());
+
+ // a memory optimization: Just store the layout information
+ // when only edit
+ if (kind == Undo::EDIT){
+ //tmppar2->text.clear();
+ tmppar2->clearContents();
+ }
+
+ undopar = tmppar2;
+
+ while (tmppar != end && tmppar->next()) {
+ tmppar = tmppar->next();
+ tmppar2->next(tmppar->Clone());
+ tmppar2->next()->id(tmppar->id());
+ // a memory optimization: Just store the layout
+ // information when only edit
+ if (kind == Undo::EDIT){
+ //tmppar2->next->text.clear();
+ tmppar2->clearContents();
+ }
+ tmppar2->next()->previous(tmppar2);
+ tmppar2 = tmppar2->next();
+ }
+ tmppar2->next(0);
+ } else
+ undopar = 0; // nothing to replace (undo of delete maybe)
+