mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-12 16:50:39 +00:00
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
This commit is contained in:
parent
4ab7fb2a49
commit
4cda8fb292
@ -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<DocumentClass *>(dc);
|
||||
cutstack.push(make_pair(copy_pars, d));
|
||||
|
@ -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<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
|
||||
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
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user