#include "BufferParams.h"
#include "buffer_funcs.h"
#include "Cursor.h"
+#include "CutAndPaste.h"
+#include "ErrorList.h"
#include "Paragraph.h"
#include "ParagraphList.h"
#include "Text.h"
#include "mathed/MathData.h"
#include "insets/Inset.h"
+#include "insets/InsetText.h"
#include "support/debug.h"
#include "support/gettext.h"
size_t group_id_;
/// Current group nesting nevel.
size_t group_level_;
+ /// the position of cursor before the group was created
+ CursorData group_cur_before_;
};
LYXERR(Debug::UNDO, "Create undo element of group " << group_id_);
// create the position information of the Undo entry
- UndoElement undo(kind, cur_before, cell, from, end, 0, 0,
- buffer_.isClean(), group_id_);
+ UndoElement undo(kind,
+ group_cur_before_.empty() ? cur_before : group_cur_before_,
+ cell, from, end, 0, 0, buffer_.isClean(), group_id_);
// fill in the real data to be saved
if (cell.inMathed()) {
void Undo::Private::doRecordUndoBufferParams(CursorData const & cur_before,
- UndoElementStack & stack)
+ UndoElementStack & stack)
{
if (!group_level_) {
LYXERR0("There is no group open (creating one)");
LYXERR(Debug::UNDO, "Create full buffer undo element of group " << group_id_);
// create the position information of the Undo entry
- UndoElement undo(cur_before, buffer_.params(), buffer_.isClean(),
+ UndoElement undo(group_cur_before_.empty() ? cur_before : group_cur_before_,
+ buffer_.params(), buffer_.isClean(),
group_id_);
// push the undo entry to undo stack
// This is a params undo element
delete otherstack.top().bparams;
otherstack.top().bparams = new BufferParams(buffer_.params());
+ DocumentClassConstPtr olddc = buffer_.params().documentClassPtr();
buffer_.params() = *undo.bparams;
+ // The error list is not supposed to be helpful here.
+ ErrorList el;
+ cap::switchBetweenClasses(olddc, buffer_.params().documentClassPtr(),
+ static_cast<InsetText &>(buffer_.inset()), el);
+ LATTEST(el.empty());
} 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
}
+void Undo::beginUndoGroup(CursorData const & cur_before)
+{
+ beginUndoGroup();
+ if (d->group_cur_before_.empty())
+ d->group_cur_before_ = cur_before;
+}
+
+
void Undo::endUndoGroup()
{
if (d->group_level_ == 0) {
--d->group_level_;
if (d->group_level_ == 0) {
// real end of the group
+ d->group_cur_before_ = CursorData();
LYXERR(Debug::UNDO, "-------End of group " << d->group_id_);
}
}
-void Undo::endUndoGroup(CursorData const & cur)
+void Undo::endUndoGroup(CursorData const & cur_after)
{
endUndoGroup();
if (!d->undostack_.empty() && d->undostack_.top().cur_after.empty())
- d->undostack_.top().cur_after = cur;
+ d->undostack_.top().cur_after = cur_after;
}