X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FUndo.cpp;h=a479728ebde2b280e519e3c09734f292f709386f;hb=7b652117d6c956edd17f84d7d22a96419e7eccdc;hp=772b9d4745126629e62bf064af10e980ae8aa5d1;hpb=a7896cb190167fe7f8b63e6e7108fa8477e857ae;p=lyx.git diff --git a/src/Undo.cpp b/src/Undo.cpp index 772b9d4745..a479728ebd 100644 --- a/src/Undo.cpp +++ b/src/Undo.cpp @@ -21,6 +21,8 @@ #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" @@ -29,6 +31,7 @@ #include "mathed/MathData.h" #include "insets/Inset.h" +#include "insets/InsetText.h" #include "support/debug.h" #include "support/gettext.h" @@ -235,6 +238,8 @@ struct Undo::Private 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_; }; @@ -340,8 +345,9 @@ void Undo::Private::doRecordUndo(UndoKind kind, 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()) { @@ -390,7 +396,7 @@ void Undo::Private::recordUndo(UndoKind kind, void Undo::Private::doRecordUndoBufferParams(CursorData const & cur_before, - UndoElementStack & stack) + UndoElementStack & stack) { if (!group_level_) { LYXERR0("There is no group open (creating one)"); @@ -399,7 +405,8 @@ void Undo::Private::doRecordUndoBufferParams(CursorData const & cur_before, 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 @@ -449,7 +456,13 @@ void Undo::Private::doTextUndoOrRedo(CursorData & cur, UndoElementStack & 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(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 @@ -555,6 +568,14 @@ void Undo::beginUndoGroup() } +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) { @@ -564,16 +585,17 @@ void Undo::endUndoGroup() --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; } @@ -621,6 +643,13 @@ void Undo::recordUndoFullBuffer(CursorData const & cur) /// UndoGroupHelper class stuff +/** FIXME: handle restarted groups + * It may happen that the buffers are visited in order buffer1, + * buffer2, buffer1. In this case, we want to have only one undo group + * in buffer1. One solution is to replace buffer_ with a set, + * but I am not sure yet how to do it. A use case is + * InsetLabel::updateReferences. + */ void UndoGroupHelper::resetBuffer(Buffer * buf) { if (buf == buffer_)