]> git.lyx.org Git - features.git/commitdiff
Fix outliner crash reported by Vincent.
authorRichard Heck <rgheck@comcast.net>
Sat, 9 May 2009 15:49:09 +0000 (15:49 +0000)
committerRichard Heck <rgheck@comcast.net>
Sat, 9 May 2009 15:49:09 +0000 (15:49 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29583 a592a061-630c-0410-9148-cb99ea01b6c8

src/Text3.cpp

index b95e84d50341f31893383d87e55219fbe3835d70..c7392600e161d6e8f1cb2701c6dd99f53338af26 100644 (file)
@@ -311,12 +311,12 @@ static void outline(OutlineOp mode, Cursor & cur)
        Buffer & buf = *cur.buffer();
        pit_type & pit = cur.pit();
        ParagraphList & pars = buf.text().paragraphs();
-       ParagraphList::iterator bgn = pars.begin();
+       ParagraphList::iterator const bgn = pars.begin();
        // The first paragraph of the area to be copied:
        ParagraphList::iterator start = boost::next(bgn, pit);
        // The final paragraph of area to be copied:
        ParagraphList::iterator finish = start;
-       ParagraphList::iterator end = pars.end();
+       ParagraphList::iterator const end = pars.end();
 
        DocumentClass const & tc = buf.params().documentClass();
 
@@ -333,6 +333,10 @@ static void outline(OutlineOp mode, Cursor & cur)
                        break;
        }
 
+       // Do we need to set insets' buffer_ members, because we copied
+       // some stuff? We'll assume we do and reset it otherwise.
+       bool setBuffers = true;
+
        switch (mode) {
                case OutlineUp: {
                        if (start == pars.begin())
@@ -360,7 +364,7 @@ static void outline(OutlineOp mode, Cursor & cur)
                        start = boost::next(pars.begin(), deletepit);
                        pit = newpit;
                        pars.erase(start, finish);
-                       return;
+                       break;
                }
                case OutlineDown: {
                        if (finish == end)
@@ -383,7 +387,7 @@ static void outline(OutlineOp mode, Cursor & cur)
                        start = boost::next(bgn, pit);
                        pit = newpit - len;
                        pars.erase(start, finish);
-                       return;
+                       break;
                }
                case OutlineIn: {
                        pit_type const len = distance(start, finish);
@@ -402,7 +406,8 @@ static void outline(OutlineOp mode, Cursor & cur)
                                        }
                                }
                        }
-                       return;
+                       setBuffers = false;
+                       break;
                }
                case OutlineOut: {
                        pit_type const len = distance(start, finish);
@@ -421,9 +426,20 @@ static void outline(OutlineOp mode, Cursor & cur)
                                        }
                                }
                        }
-                       return;
+                       setBuffers = false;
+                       break;
                }
        }
+       if (setBuffers)
+               // FIXME This only really needs doing for the newly introduced 
+               // paragraphs. Something like:
+               //      pit_type const numpars = distance(start, finish);
+               //      start = boost::next(bgn, pit);
+               //      finish = boost::next(start, numpars);
+               //      for (; start != finish; ++start)
+               //              start->setBuffer(buf);
+               // But while this seems to work, it is kind of fragile.
+               buf.inset().setBuffer(buf);
 }