- if (!undo_frozen) {
- otherstack.push(undo);
- otherstack.top().pars.clear();
- ParIterator pit = num2pit(bv, undo.text);
- ParagraphList & plist = pit.plist();
- if (undo.first_par + undo.end_par <= int(plist.size())) {
- ParagraphList::iterator first = plist.begin();
- advance(first, undo.first_par);
- ParagraphList::iterator last = plist.begin();
- advance(last, plist.size() - undo.end_par + 1);
- otherstack.top().pars.insert(otherstack.top().pars.begin(), first, last);
- }
- LyXText * text = pit2text(bv, pit);
- otherstack.top().cursor_pos = text->cursor.pos();
- otherstack.top().cursor_par = text->cursor.par();
- lyxerr << " undo other: " << otherstack.top() << std::endl;
+ // We will store in otherstack the part of the document under 'undo'
+ Buffer * buf = bv.buffer();
+ DocIterator cell_dit = undo.cell.asDocIterator(&buf->inset());
+
+ doRecordUndo(Undo::ATOMIC, cell_dit,
+ undo.from, cell_dit.lastpit() - undo.end, bv.cursor(),
+ undo.bparams, undo.isFullBuffer,
+ otherstack);
+
+ // This does the actual undo/redo.
+ //lyxerr << "undo, performing: " << undo << std::endl;
+ DocIterator dit = undo.cell.asDocIterator(&buf->inset());
+ if (undo.isFullBuffer) {
+ // This is a full document
+ otherstack.top().bparams = buf->params();
+ buf->params() = undo.bparams;
+ buf->paragraphs() = undo.pars;
+ } else if (dit.inMathed()) {
+ // We stored the full cell here as there is not much to be
+ // gained by storing just 'a few' paragraphs (most if not
+ // all math inset cells have just one paragraph!)
+ //lyxerr << "undo.array=" << undo.array <<endl;
+ asArray(undo.array, dit.cell());
+ } else {
+ // Some finer machinery is needed here.
+ LyXText * text = dit.text();
+ BOOST_ASSERT(text);
+ ParagraphList & plist = text->paragraphs();
+
+ // remove new stuff between first and last
+ ParagraphList::iterator first = plist.begin();
+ advance(first, undo.from);
+ ParagraphList::iterator last = plist.begin();
+ advance(last, plist.size() - undo.end);
+ plist.erase(first, last);
+
+ // re-insert old stuff instead
+ first = plist.begin();
+ advance(first, undo.from);
+
+ // this ugly stuff is needed until we get rid of the
+ // inset_owner backpointer
+ ParagraphList::iterator pit = undo.pars.begin();
+ ParagraphList::iterator const end = undo.pars.end();
+ for (; pit != end; ++pit)
+ pit->setInsetOwner(dit.realInset());
+ plist.insert(first, undo.pars.begin(), undo.pars.end());