Fix bug #5390. Copy from a deleted section with change tracking.

Do not accept the changes in the selection, if it is completely deleted.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29672 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Vincent van Ravesteijn 2009-05-14 22:21:05 +00:00
parent 1f3b4e24af
commit f05504f5ef
7 changed files with 54 additions and 4 deletions

View File

@ -256,6 +256,24 @@ Change const & Changes::lookup(pos_type const pos) const
}
bool Changes::isFullyDeleted(pos_type start, pos_type end) const
{
ChangeTable::const_iterator it = table_.begin();
ChangeTable::const_iterator const itend = table_.end();
for (; it != itend; ++it) {
if (it->range.contains(Range(start, end))) {
LYXERR(Debug::CHANGES, "range ("
<< start << ", " << end << ") fully contains ("
<< it->range.start << ", " << it->range.end
<< ") of type " << it->change.type);
return it->change.type == Change::DELETED;
}
}
return false;
}
bool Changes::isChanged(pos_type const start, pos_type const end) const
{
ChangeTable::const_iterator it = table_.begin();

View File

@ -94,6 +94,9 @@ public:
/// return true if there is a change in the given range (excluding end)
bool isChanged(pos_type start, pos_type end) const;
/// return true if the whole range is deleted
bool isFullyDeleted(pos_type const start, pos_type const end) const;
/// output latex to mark a transition between two change types
/// returns length of text outputted
static int latexMarkChange(odocstream & os, BufferParams const & bparams,

View File

@ -431,14 +431,16 @@ void copySelectionHelper(Buffer const & buf, ParagraphList const & pars,
// ERT paragraphs have the Language latex_language.
// This is invalid outside of ERT, so we need to change it
// to the buffer language.
if (it->ownerCode() == ERT_CODE || it->ownerCode() == LISTINGS_CODE) {
if (it->ownerCode() == ERT_CODE || it->ownerCode() == LISTINGS_CODE)
it->changeLanguage(buf.params(), latex_language, buf.language());
}
it->setInsetOwner(0);
}
// do not copy text (also nested in insets) which is marked as deleted
acceptChanges(copy_pars, buf.params());
// do not copy text (also nested in insets) which is marked as deleted,
// unless the whole selection was deleted
if (!isFullyDeleted(copy_pars))
acceptChanges(copy_pars, buf.params());
DocumentClass * d = const_cast<DocumentClass *>(dc);
cutstack.push(make_pair(copy_pars, d));

View File

@ -288,6 +288,15 @@ void Paragraph::addChangesToToc(DocIterator const & cdit,
}
bool Paragraph::isFullyDeleted(pos_type start, pos_type end) const
{
LASSERT(start >= 0 && start <= size(), /**/);
LASSERT(end > start && end <= size() + 1, /**/);
return d->changes_.isFullyDeleted(start, end);
}
bool Paragraph::isChanged(pos_type start, pos_type end) const
{
LASSERT(start >= 0 && start <= size(), /**/);

View File

@ -203,6 +203,8 @@ public:
bool isInserted(pos_type pos) const;
/// is there a deletion at the given pos ?
bool isDeleted(pos_type pos) const;
/// is the whole paragraph deleted ?
bool isFullyDeleted(pos_type start, pos_type end) const;
/// will the paragraph be physically merged with the next
/// one if the imaginary end-of-par character is logically deleted?

View File

@ -305,6 +305,20 @@ Font const outerFont(pit_type par_offset, ParagraphList const & pars)
}
bool isFullyDeleted(ParagraphList const & pars)
{
pit_type const pars_size = static_cast<pit_type>(pars.size());
// check all paragraphs
for (pit_type pit = 0; pit < pars_size; ++pit) {
if (!pars[pit].empty()) // prevent assertion failure
if (!pars[pit].isFullyDeleted(0, pars[pit].size()))
return false;
}
return true;
}
void acceptChanges(ParagraphList & pars, BufferParams const & bparams)
{
pit_type pars_size = static_cast<pit_type>(pars.size());

View File

@ -73,6 +73,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);
/// return true if the whole ParagraphList is deleted
bool isFullyDeleted(ParagraphList const & pars);
} // namespace lyx