commit 66e1819ad170bd2fa0096872cd8cd20c123eba59
Author: Richard Heck <rgh...@lyx.org>
Date:   Sun Oct 15 22:22:22 2017 -0400

    Fix the way that the Buffer gets set on undo.
    
    Previously, we went through the entire Buffer and set it for every
    single inset. Now we just do it for the insets we pasted.
---
 src/Buffer.cpp |    6 ------
 src/Buffer.h   |    4 ----
 src/Undo.cpp   |   12 +++++++++---
 3 files changed, 9 insertions(+), 13 deletions(-)

diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index c4ce8ea..89a76b5 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -4699,12 +4699,6 @@ void Buffer::bufferErrors(TeXErrors const & terr, 
ErrorList & errorList) const
 }
 
 
-void Buffer::setBuffersForInsets() const
-{
-       inset().setBuffer(const_cast<Buffer &>(*this));
-}
-
-
 void Buffer::updateBuffer(UpdateScope scope, UpdateType utype) const
 {
        LBUFERR(!text().paragraphs().empty());
diff --git a/src/Buffer.h b/src/Buffer.h
index 165f5d8..6d50e70 100644
--- a/src/Buffer.h
+++ b/src/Buffer.h
@@ -719,10 +719,6 @@ public:
        /// return a list of all used branches (also in children)
        void getUsedBranches(std::list<docstring> &, bool const from_master = 
false) const;
 
-       /// sets the buffer_ member for every inset in this buffer.
-       // FIXME This really shouldn't be needed, but at the moment it's not
-       // clear how to do it just for the individual pieces we need.
-       void setBuffersForInsets() const;
        /// Updates screen labels and some other information associated with
        /// insets and paragraphs. Actually, it's more like a general "recurse
        /// through the Buffer" routine, that visits all the insets and 
paragraphs.
diff --git a/src/Undo.cpp b/src/Undo.cpp
index a479728..31072ba 100644
--- a/src/Undo.cpp
+++ b/src/Undo.cpp
@@ -497,6 +497,15 @@ void Undo::Private::doTextUndoOrRedo(CursorData & cur, 
UndoElementStack & stack,
                for (; pit != end; ++pit)
                        pit->setInsetOwner(dit.realInset());
                plist.insert(first, undo.pars->begin(), undo.pars->end());
+
+               // set the buffers for insets we created
+               ParagraphList::iterator fpit = plist.begin();
+               advance(fpit, undo.from);
+               ParagraphList::iterator fend = fpit;
+               advance(fend, undo.pars->size());
+               for (; fpit != fend; ++fpit)
+                       fpit->setBuffer(buffer_);
+
                delete undo.pars;
                undo.pars = 0;
        }
@@ -531,9 +540,6 @@ 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);
-
-       // Adapt the new material to current buffer.
-       buffer_.setBuffersForInsets(); // FIXME This shouldn't be here.
        return true;
 }
 

Reply via email to