From 4cda8fb292ad99a8b2fc8adc4b00ab2bc61a81a5 Mon Sep 17 00:00:00 2001 From: Vincent van Ravesteijn Date: Mon, 14 Jun 2010 12:23:52 +0000 Subject: [PATCH] branch: Fix bug #6744: Crash when copying an inset from a deleted section. We need to reject the changes in when copying from a fully deleted section. see r34583. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_6_X@34650 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/CutAndPaste.cpp | 2 ++ src/paragraph_funcs.cpp | 51 +++++++++++++++++++++++++++++------------ src/paragraph_funcs.h | 2 ++ 3 files changed, 40 insertions(+), 15 deletions(-) diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp index 178842f50a..7d75bde9dd 100644 --- a/src/CutAndPaste.cpp +++ b/src/CutAndPaste.cpp @@ -478,6 +478,8 @@ void copySelectionHelper(Buffer const & buf, ParagraphList const & pars, // unless the whole selection was deleted if (!isFullyDeleted(copy_pars)) acceptChanges(copy_pars, buf.params()); + else + rejectChanges(copy_pars, buf.params()); DocumentClass * d = const_cast(dc); cutstack.push(make_pair(copy_pars, d)); diff --git a/src/paragraph_funcs.cpp b/src/paragraph_funcs.cpp index 26fc7a95a3..6b1ca79841 100644 --- a/src/paragraph_funcs.cpp +++ b/src/paragraph_funcs.cpp @@ -319,36 +319,57 @@ bool isFullyDeleted(ParagraphList const & pars) } -void acceptChanges(ParagraphList & pars, BufferParams const & bparams) +static void acceptOrRejectChanges(ParagraphList & pars, + BufferParams const & bparams, Text::ChangeOp op) { pit_type pars_size = static_cast(pars.size()); - // first, accept changes within each individual paragraph - // (do not consider end-of-par) + // first, accept or reject changes within each individual + // paragraph (do not consider end-of-par) for (pit_type pit = 0; pit < pars_size; ++pit) { - if (!pars[pit].empty()) // prevent assertion failure - pars[pit].acceptChanges(bparams, 0, pars[pit].size()); + // prevent assertion failure + if (!pars[pit].empty()) { + if (op == Text::ACCEPT) + pars[pit].acceptChanges(bparams, 0, pars[pit].size()); + else + pars[pit].rejectChanges(bparams, 0, pars[pit].size()); + } } - // next, accept imaginary end-of-par characters + // next, accept or reject imaginary end-of-par characters for (pit_type pit = 0; pit < pars_size; ++pit) { pos_type pos = pars[pit].size(); - if (pars[pit].isInserted(pos)) { - pars[pit].setChange(pos, Change(Change::UNCHANGED)); - } else if (pars[pit].isDeleted(pos)) { - if (pit == pars_size - 1) { - // we cannot remove a par break at the end of the last - // paragraph; instead, we mark it unchanged + if (!pars[pit].isUnchanged(pos)) { + // keep the end-of-par char if it is inserted and accepted + // or when it is deleted and rejected. + if (pars[pit].isInserted(pos) == (op == Text::ACCEPT)) { pars[pit].setChange(pos, Change(Change::UNCHANGED)); } else { - mergeParagraph(bparams, pars, pit); - --pit; - --pars_size; + if (pit == pars_size - 1) { + // we cannot remove a par break at the end of the last + // paragraph; instead, we mark it unchanged + pars[pit].setChange(pos, Change(Change::UNCHANGED)); + } else { + mergeParagraph(bparams, pars, pit); + --pit; + --pars_size; + } } } } } +void acceptChanges(ParagraphList & pars, BufferParams const & bparams) +{ + acceptOrRejectChanges(pars, bparams, Text::ACCEPT); +} + + +void rejectChanges(ParagraphList & pars, BufferParams const & bparams) +{ + acceptOrRejectChanges(pars, bparams, Text::REJECT); +} + } // namespace lyx diff --git a/src/paragraph_funcs.h b/src/paragraph_funcs.h index 1e2fec98b8..74d768d56a 100644 --- a/src/paragraph_funcs.h +++ b/src/paragraph_funcs.h @@ -72,6 +72,8 @@ Font const outerFont(pit_type par_offset, ParagraphList const & pars); /// accept the changes within the complete ParagraphList void acceptChanges(ParagraphList & pars, BufferParams const & bparams); +/// reject the changes within the complete ParagraphList +void rejectChanges(ParagraphList & pars, BufferParams const & bparams); /// return true if the whole ParagraphList is deleted bool isFullyDeleted(ParagraphList const & pars);