]> git.lyx.org Git - features.git/commitdiff
Fix bug #6744: Crash when copying an inset from a deleted section.
authorVincent van Ravesteijn <vfr@lyx.org>
Tue, 1 Jun 2010 16:13:54 +0000 (16:13 +0000)
committerVincent van Ravesteijn <vfr@lyx.org>
Tue, 1 Jun 2010 16:13:54 +0000 (16:13 +0000)
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

src/CutAndPaste.cpp
src/Text.cpp
src/Text.h

index 4cc10d59f4dee15e200be9cd59320eb9244c6cc6..07274a39a040158e90637523b7266c351d130a55 100644 (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
index 6cc354dfd7a93c34f4ad91f021b6cdab6ba597a4..8f106b42c6f49e9c91742d1ce09a16d7c33b19fb 100644 (file)
@@ -259,37 +259,59 @@ 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
-                       pars[pit].acceptChanges(0, pars[pit].size());
+               // 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)) {
-                       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].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 {
-                               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);
+}
+
+
 InsetText const & Text::inset() const
 {
        return *owner_;
index e6826e28938248e9140fd812c50699e74f114973..e3421e2e5f52183c67df98b326e75d27fec2af23 100644 (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