From 0bee8a3b5633cc89661cf7d73c96a18365e73218 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrgen=20Spitzm=C3=BCller?= Date: Sat, 7 Mar 2009 11:45:41 +0000 Subject: [PATCH] * CutAndPaste.cpp: - correctly set buffer on paste. This fixes a crash on pasting branches within child documents (bug 5813) (patch by rgheck) git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@28711 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/CutAndPaste.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp index 36cbd7ab42..610f71caf8 100644 --- a/src/CutAndPaste.cpp +++ b/src/CutAndPaste.cpp @@ -221,7 +221,10 @@ pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist, InsetIterator const i_end = inset_iterator_end(in); for (InsetIterator it = inset_iterator_begin(in); it != i_end; ++it) { - // Insets store buffer references so need updating. + // Insets store buffer references so need updating. + // FIXME This code can probably be deleted. The insets will get copied + // when they are pasted, at which point their buffer_ members will get + // set back to zero. it->setBuffer(const_cast(buffer)); switch (it->lyxCode()) { @@ -297,16 +300,19 @@ pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist, // merge the first par of the insertion with the current par mergeParagraph(buffer.params(), pars, pit); } - //FIXME: We should call setBuffer() on each inserted paragraph. - // instead, we call setBuffer() for the main inset at the beginning - // of updateLabels() - - pit_type last_paste = pit + insertion.size() - 1; // Store the new cursor position. + pit_type last_paste = pit + insertion.size() - 1; + pit_type startpit = pit; pit = last_paste; pos = pars[last_paste].size(); + // Set paragraph buffers. It's important to do this right away + // before something calls Inset::buffer() and causes a crash. + for (pit_type p = startpit; p <= pit; ++p) + pars[p].setBuffer(const_cast(buffer)); + + // Join (conditionally) last pasted paragraph with next one, i.e., // the tail of the spliced document paragraph if (!empty && last_paste + 1 != pit_type(pars.size())) { -- 2.39.2