]> git.lyx.org Git - lyx.git/blobdiff - src/Undo.cpp
GuiSetBorder: Fix drawing glitch with trimmed lines
[lyx.git] / src / Undo.cpp
index 2eb35a29d04de95fc5f4f6161d4c310246d7343b..a9e0bba8e29a0c4c1ff0019b6fd1996270f85522 100644 (file)
@@ -18,6 +18,7 @@
 #include "Undo.h"
 
 #include "Buffer.h"
+#include "BufferList.h"
 #include "BufferParams.h"
 #include "buffer_funcs.h"
 #include "Cursor.h"
@@ -202,10 +203,10 @@ struct Undo::Private
                                   group_id_(0), group_level_(0) {}
 
        // Do one undo/redo step
-       void doTextUndoOrRedo(CursorData & cur, UndoElementStack & stack,
+       void doUndoRedoAction(CursorData & cur, UndoElementStack & stack,
                              UndoElementStack & otherStack);
        // Apply one undo/redo group. Returns false if no undo possible.
-       bool textUndoOrRedo(CursorData & cur, bool isUndoOperation);
+       bool undoRedoAction(CursorData & cur, bool isUndoOperation);
 
        ///
        void doRecordUndo(UndoKind kind,
@@ -429,7 +430,7 @@ void Undo::Private::recordUndoBufferParams(CursorData const & cur)
 }
 
 
-void Undo::Private::doTextUndoOrRedo(CursorData & cur, UndoElementStack & stack, UndoElementStack & otherstack)
+void Undo::Private::doUndoRedoAction(CursorData & cur, UndoElementStack & stack, UndoElementStack & otherstack)
 {
        // Adjust undo stack and get hold of current undo data.
        UndoElement & undo = stack.top();
@@ -471,6 +472,7 @@ void Undo::Private::doTextUndoOrRedo(CursorData & cur, UndoElementStack & stack,
                //LYXERR0("undo.array: " << *undo.array);
                LBUFERR(undo.array);
                dit.cell().swap(*undo.array);
+               dit.inset().setBuffer(buffer_);
                delete undo.array;
                undo.array = 0;
        } else {
@@ -526,7 +528,7 @@ void Undo::Private::doTextUndoOrRedo(CursorData & cur, UndoElementStack & stack,
 }
 
 
-bool Undo::Private::textUndoOrRedo(CursorData & cur, bool isUndoOperation)
+bool Undo::Private::undoRedoAction(CursorData & cur, bool isUndoOperation)
 {
        undo_finished_ = true;
 
@@ -540,7 +542,7 @@ bool Undo::Private::textUndoOrRedo(CursorData & cur, bool isUndoOperation)
 
        const size_t gid = stack.top().group_id;
        while (!stack.empty() && stack.top().group_id == gid)
-               doTextUndoOrRedo(cur, stack, otherstack);
+               doUndoRedoAction(cur, stack, otherstack);
        return true;
 }
 
@@ -552,15 +554,15 @@ void Undo::finishUndo()
 }
 
 
-bool Undo::textUndo(CursorData & cur)
+bool Undo::undoAction(CursorData & cur)
 {
-       return d->textUndoOrRedo(cur, true);
+       return d->undoRedoAction(cur, true);
 }
 
 
-bool Undo::textRedo(CursorData & cur)
+bool Undo::redoAction(CursorData & cur)
 {
-       return d->textUndoOrRedo(cur, false);
+       return d->undoRedoAction(cur, false);
 }
 
 
@@ -569,7 +571,8 @@ void Undo::beginUndoGroup()
        if (d->group_level_ == 0) {
                // create a new group
                ++d->group_id_;
-               LYXERR(Debug::UNDO, "+++++++Creating new group " << d->group_id_);
+               LYXERR(Debug::UNDO, "+++++++ Creating new group " << d->group_id_
+                      << " for buffer " << &d->buffer_);
        }
        ++d->group_level_;
 }
@@ -593,7 +596,8 @@ void Undo::endUndoGroup()
        if (d->group_level_ == 0) {
                // real end of the group
                d->group_cur_before_ = CursorData();
-               LYXERR(Debug::UNDO, "-------End of group " << d->group_id_);
+               LYXERR(Debug::UNDO, "------- End of group " << d->group_id_
+                      << " of buffer " << &d->buffer_);
        }
 }
 
@@ -606,6 +610,24 @@ void Undo::endUndoGroup(CursorData const & cur_after)
 }
 
 
+void Undo::splitUndoGroup(CursorData const & cur)
+{
+       size_t const level = d->group_level_;
+       d->group_level_ = 1;
+       endUndoGroup(cur);
+       beginUndoGroup(cur);
+       d->group_level_ = level;
+}
+
+
+bool Undo::activeUndoGroup() const
+{
+       return d->group_level_ > 0
+               && !d->undostack_.empty()
+               && d->undostack_.top().group_id == d->group_id_;
+}
+
+
 void Undo::recordUndo(CursorData const & cur, UndoKind kind)
 {
        d->recordUndo(kind, cur, cur.pit(), cur.pit(), cur);
@@ -665,7 +687,8 @@ UndoGroupHelper::UndoGroupHelper(Buffer * buf) : d(new UndoGroupHelper::Impl)
 UndoGroupHelper::~UndoGroupHelper()
 {
        for (Buffer * buf : d->buffers_)
-               buf->undo().endUndoGroup();
+               if (theBufferList().isLoaded(buf) || theBufferList().isInternal(buf))
+                       buf->undo().endUndoGroup();
        delete d;
 }