]> git.lyx.org Git - features.git/commitdiff
Use the proper buffer when recording undo
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 4 Jul 2017 14:34:34 +0000 (16:34 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Sun, 3 Sep 2017 16:35:37 +0000 (18:35 +0200)
The code in InsetLabel::updateReferences code changes reference insets
in potentially several buffers. When recording undo, it is important
to use the right undo stack, otherwise crashes can ensue.

Once it is done, it is neccessary to create undo groups as needed.
This is done using UndoGroupHelper. This demonstrates a shortcoming of
UndoGroupHelper: if a buffer is encountered in two seperate
occasions, two undo groups will be created for this buffer. This is
not correct.

Fixes bug #10643.

(cherry picked from commit 4eb9b50dc642a3532d8126a93571696b3db57640)

src/Undo.cpp
src/Undo.h
src/insets/InsetLabel.cpp
status.22x

index 143af4e83ff0b9f29eac7ecc2f1abbf5e6c8ceb4..a479728ebde2b280e519e3c09734f292f709386f 100644 (file)
@@ -643,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<Buffer*>,
+ * but I am not sure yet how to do it. A use case is
+ * InsetLabel::updateReferences.
+ */
 void UndoGroupHelper::resetBuffer(Buffer * buf)
 {
        if (buf == buffer_)
index 59f3ca44fc93a58975ee459ffc9440e5889a5ac1..70897bfa28fe336f21d428b27ea62c4708bed3af 100644 (file)
@@ -135,7 +135,7 @@ private:
  */
 class UndoGroupHelper {
 public:
-       UndoGroupHelper(Buffer * buf) : buffer_(0)
+       UndoGroupHelper(Buffer * buf = 0) : buffer_(0)
        {
                resetBuffer(buf);
        }
index 553c6d7b969bac5cb09fcf1f26862c4a99509328..f4a6f08eb674ecc4c1d71bb13ba711ebde58da39 100644 (file)
@@ -109,11 +109,13 @@ void InsetLabel::updateLabelAndRefs(docstring const & new_label,
 void InsetLabel::updateReferences(docstring const & old_label,
                docstring const & new_label)
 {
+       UndoGroupHelper ugh;
        Buffer::References const & refs = buffer().references(old_label);
        Buffer::References::const_iterator it = refs.begin();
        Buffer::References::const_iterator end = refs.end();
        for (; it != end; ++it) {
-               buffer().undo().recordUndo(CursorData(it->second));
+               ugh.resetBuffer(it->second.buffer());
+               it->second.buffer()->undo().recordUndo(CursorData(it->second));
                if (it->first->lyxCode() == MATH_REF_CODE) {
                        InsetMathRef * mi = it->first->asInsetMath()->asRefInset();
                        mi->changeTarget(new_label);
index e5ee17023538fad552bd42f84a87a70ed487c3ee..cb2ba55f55e9990666e649cbe169858989c6d849 100644 (file)
@@ -84,6 +84,8 @@ What's new
 
 - Avoid crash when selecting long text (bug 10324).
 
+- Fix crash with undo and child documents (bug 10643).
+
 - Remove duplicate entries from the Symbols dialog (bug 10644).
 
 - Always show the float type in the float inset label (bug 10618).