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.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@34583 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Vincent van Ravesteijn 2010-06-01 16:13:54 +00:00
parent 5f2de40786
commit a948d13333
3 changed files with 43 additions and 16 deletions

View File

@ -539,6 +539,8 @@ void copySelectionHelper(Buffer const & buf, Text const & text,
// deleted, unless the whole selection was deleted
if (!isFullyDeleted(copy_pars))
acceptChanges(copy_pars, buf.params());
else
rejectChanges(copy_pars, buf.params());
// do some final cleanup now, to make sure that the paragraphs

View File

@ -259,24 +259,32 @@ Font const Text::outerFont(pit_type par_offset) const
}
void acceptChanges(ParagraphList & pars, BufferParams const & bparams)
static void acceptOrRejectChanges(ParagraphList & pars,
BufferParams const & bparams, Text::ChangeOp op)
{
pit_type pars_size = static_cast<pit_type>(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
// prevent assertion failure
if (!pars[pit].empty()) {
if (op == Text::ACCEPT)
pars[pit].acceptChanges(0, pars[pit].size());
else
pars[pit].rejectChanges(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)) {
if (pars[pit].isChanged(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 if (pars[pit].isDeleted(pos)) {
} else {
if (pit == pars_size - 1) {
// we cannot remove a par break at the end of the last
// paragraph; instead, we mark it unchanged
@ -289,6 +297,20 @@ void acceptChanges(ParagraphList & pars, BufferParams const & bparams)
}
}
}
}
void acceptChanges(ParagraphList & pars, BufferParams const & bparams)
{
acceptOrRejectChanges(pars, bparams, Text::ACCEPT);
}
void rejectChanges(ParagraphList & pars, BufferParams const & bparams)
{
acceptOrRejectChanges(pars, bparams, Text::REJECT);
}
InsetText const & Text::inset() const
{

View File

@ -395,6 +395,9 @@ void mergeParagraph(BufferParams const & bparams,
/// 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);
} // namespace lyx
#endif // TEXT_H