]> git.lyx.org Git - lyx.git/blobdiff - src/Undo.cpp
Fix bug 4166: Crash when middle button click on inset label
[lyx.git] / src / Undo.cpp
index 7045765769f7682121e0048cc5b52eb6491a869e..4e2ac02c88d59b5280110ce320fc3adeb2f111df 100644 (file)
@@ -79,7 +79,25 @@ struct UndoElement
                        bparams = new BufferParams(bp);
        }
        ///
-       ~UndoElement() { delete bparams; }
+       UndoElement(UndoElement const & ue)
+       {
+               kind = ue.kind;
+               cursor = ue.cursor;
+               cell = ue.cell;
+               from = ue.from;
+               end = ue.end;
+               pars = ue.pars;
+               array = ue.array;
+               bparams = ue.isFullBuffer
+                       ? new BufferParams(*ue.bparams) : ue.bparams;
+               isFullBuffer = ue.isFullBuffer;
+       }
+       ///
+       ~UndoElement()
+       {
+               if (isFullBuffer)
+                       delete bparams;
+       }
        /// Which kind of operation are we recording for?
        UndoKind kind;
        /// the position of the cursor
@@ -322,7 +340,6 @@ bool Undo::Private::textUndoOrRedo(DocIterator & cur, bool isUndoOperation)
 
        // This does the actual undo/redo.
        //LYXERR0("undo, performing: " << undo);
-       bool labelsUpdateNeeded = false;
        DocIterator dit = undo.cell.asDocIterator(&buffer_.inset());
        if (undo.isFullBuffer) {
                LASSERT(undo.pars, /**/);
@@ -369,7 +386,6 @@ bool Undo::Private::textUndoOrRedo(DocIterator & cur, bool isUndoOperation)
                plist.insert(first, undo.pars->begin(), undo.pars->end());
                delete undo.pars;
                undo.pars = 0;
-               labelsUpdateNeeded = true;
        }
        LASSERT(undo.pars == 0, /**/);
        LASSERT(undo.array == 0, /**/);
@@ -377,9 +393,8 @@ bool Undo::Private::textUndoOrRedo(DocIterator & cur, bool isUndoOperation)
        cur = undo.cursor.asDocIterator(&buffer_.inset());
        // Now that we're done with undo, we pop it off the stack.
        stack.pop();
-
-       if (labelsUpdateNeeded)
-               updateLabels(buffer_);
+       // Addapt the new material to current buffer.
+       updateLabels(buffer_);
        undo_finished_ = true;
        return true;
 }