#include "BufferView.h"
#include "lyxtext.h"
#include "paragraph.h"
+#include "ParagraphList.h"
-#include "mathed/math_support.h"
-#include "insets/updatableinset.h"
+#include "mathed/MathSupport.h"
+#include "insets/inset.h"
#include <algorithm>
-using lyx::pit_type;
+
+namespace lyx {
using std::advance;
using std::endl;
}
+bool samePar(StableDocIterator const & i1, StableDocIterator const & i2)
+{
+ StableDocIterator tmpi2 = i2;
+ tmpi2.pos() = i1.pos();
+ return i1 == tmpi2;
+}
+
+
void doRecordUndo(Undo::undo_kind kind,
DocIterator const & cell,
pit_type first_pit, pit_type last_pit,
if (!undo_finished
&& kind != Undo::ATOMIC
&& !stack.empty()
- && stack.top().cell == undo.cell
- && stack.top().kind == undo.kind
- && stack.top().from == undo.from
- && stack.top().end == undo.end)
+ && samePar(stack.top().cell, undo.cell)
+ && stack.top().kind == undo.kind
+ && stack.top().from == undo.from
+ && stack.top().end == undo.end)
return;
// fill in the real data to be saved
if (cell.inMathed()) {
// simply use the whole cell
- undo.array = asString(cell.cell());
+ undo.array = to_utf8(asString(cell.cell()));
} else {
// some more effort needed here as 'the whole cell' of the
// main LyXText _is_ the whole document.
// record the relevant paragraphs
LyXText const * text = cell.text();
BOOST_ASSERT(text);
- ParagraphList & plist = text->paragraphs();
- ParagraphList::iterator first = plist.begin();
+ ParagraphList const & plist = text->paragraphs();
+ ParagraphList::const_iterator first = plist.begin();
advance(first, first_pit);
- ParagraphList::iterator last = plist.begin();
+ ParagraphList::const_iterator last = plist.begin();
advance(last, last_pit + 1);
undo.pars = ParagraphList(first, last);
}
// 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!)
- asArray(undo.array, dit.cell());
+ //lyxerr << "undo.array=" << undo.array <<endl;
+ // FIXME UNICODE
+ asArray(from_utf8(undo.array), dit.cell());
} else {
// Some finer machinery is needed here.
LyXText * text = dit.text();
// this ugly stuff is needed until we get rid of the
// inset_owner backpointer
- ParagraphList::const_iterator pit = undo.pars.begin();
- ParagraphList::const_iterator end = undo.pars.end();
+ ParagraphList::iterator pit = undo.pars.begin();
+ ParagraphList::iterator const end = undo.pars.end();
for (; pit != end; ++pit)
- const_cast<Paragraph &>(*pit).setInsetOwner(
- dynamic_cast<UpdatableInset *>(&dit.inset()));
+ pit->setInsetOwner(dit.realInset());
plist.insert(first, undo.pars.begin(), undo.pars.end());
}
{
LCursor c = cur;
c.pop();
- recordUndo(c, kind);
+ Buffer * buf = cur.bv().buffer();
+ doRecordUndo(kind, c, c.pit(), c.pit(), cur,
+ buf->params(), false, buf->undostack());
}
);
undo_finished = false;
}
+
+
+} // namespace lyx