- if (!undo_frozen) {
- otherstack.push(undo);
- otherstack.top().pars.clear();
- ParIterator pit = num2pit(buf, 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);
- }
- otherstack.top().cursor_pos = bv.cursor().pos();
- otherstack.top().cursor_par = bv.cursor().par();
- lyxerr << " undo other: " << otherstack.top() << std::endl;
- }
-
- freezeUndo();
- bool const ret = performUndoOrRedo(bv, undo);
- unFreezeUndo();
- return ret;
-}
+ // 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();