#include "Undo.h"
#include "Buffer.h"
+#include "BufferList.h"
#include "BufferParams.h"
#include "buffer_funcs.h"
#include "Cursor.h"
#include <algorithm>
#include <deque>
+#include <set>
using namespace std;
using namespace lyx::support;
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->setInsetBuffers(buffer_);
+
delete undo.pars;
undo.pars = 0;
}
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;
}
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_;
}
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_);
}
}
/// 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.
- */
+class UndoGroupHelper::Impl {
+ friend class UndoGroupHelper;
+ set<Buffer *> buffers_;
+};
+
+
+UndoGroupHelper::UndoGroupHelper(Buffer * buf) : d(new UndoGroupHelper::Impl)
+{
+ resetBuffer(buf);
+}
+
+
+UndoGroupHelper::~UndoGroupHelper()
+{
+ for (Buffer * buf : d->buffers_)
+ if (theBufferList().isLoaded(buf) || theBufferList().isInternal(buf))
+ buf->undo().endUndoGroup();
+ delete d;
+}
+
void UndoGroupHelper::resetBuffer(Buffer * buf)
{
- if (buf == buffer_)
- return;
- if (buffer_)
- buffer_->undo().endUndoGroup();
- buffer_ = buf;
- if (buffer_)
- buffer_->undo().beginUndoGroup();
+ if (buf && d->buffers_.count(buf) == 0) {
+ d->buffers_.insert(buf);
+ buf->undo().beginUndoGroup();
+ }
}