]> git.lyx.org Git - lyx.git/blobdiff - src/Undo.cpp
Account for old versions of Pygments
[lyx.git] / src / Undo.cpp
index 772b9d4745126629e62bf064af10e980ae8aa5d1..143af4e83ff0b9f29eac7ecc2f1abbf5e6c8ceb4 100644 (file)
@@ -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<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
@@ -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;
 }