]> git.lyx.org Git - features.git/commitdiff
Use paragraph iterators in CutAndPaste::SwitchLayoutsBetweenClasses
authorDekel Tsur <dekelts@tau.ac.il>
Fri, 7 Dec 2001 18:40:24 +0000 (18:40 +0000)
committerDekel Tsur <dekelts@tau.ac.il>
Fri, 7 Dec 2001 18:40:24 +0000 (18:40 +0000)
and in BufferView::removeAutoInsets

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3166 a592a061-630c-0410-9148-cb99ea01b6c8

src/BufferView2.C
src/ChangeLog
src/CutAndPaste.C
src/iterators.C

index 822bfde0b7bb0f719268f0868217de1db640e2ec..05b40ef781c48de9c51d230392d7f0d7452bfe16 100644 (file)
@@ -102,23 +102,28 @@ bool BufferView::insertLyXFile(string const & filen)
 
 bool BufferView::removeAutoInsets()
 {
-       Paragraph * par = buffer()->paragraph;
-
        LyXCursor tmpcursor = text->cursor;
        LyXCursor cursor;
+       bool found = false;
 
-       bool a = false;
-
-       while (par) {
+       ParIterator end = buffer()->par_iterator_end();
+       for (ParIterator it = buffer()->par_iterator_begin();
+            it != end; ++it) {
+               Paragraph * par = *it;
                // this has to be done before the delete
-               text->setCursor(this, cursor, par, 0);
-               if (par->autoDeleteInsets()){
-                       a = true;
-                       text->redoParagraphs(this, cursor,
-                                            cursor.par()->next());
-                       text->fullRebreak(this);
+               if (par->autoDeleteInsets()) {
+                       found = true;
+#ifdef WITH_WARNINGS
+#warning FIXME
+#endif
+                       // The test it.size()==1 was needed to prevent crashes.
+                       if (it.size() == 1) {
+                               text->setCursor(this, cursor, par, 0);
+                               text->redoParagraphs(this, cursor,
+                                                    cursor.par()->next());
+                               text->fullRebreak(this);
+                       }
                }
-               par = par->next();
        }
 
        // avoid forbidden cursor positions caused by error removing
@@ -127,7 +132,7 @@ bool BufferView::removeAutoInsets()
 
        text->setCursorIntern(this, tmpcursor.par(), tmpcursor.pos());
 
-       return a;
+       return found;
 }
 
 
index b76f096bebc8de9b804845fad7d287727c50168a..6f2bc66fec5eb6cdc271ad74085cd00c3e9a3ab0 100644 (file)
@@ -1,3 +1,12 @@
+2001-12-07  Dekel Tsur  <dekelts@tau.ac.il>
+
+       * iterators.C (operator++): Make the iterator more robust
+
+       * BufferView2.C (removeAutoInsets): Use paragraph iterators
+       (John's patch)
+       * CutAndPaste.C (SwitchLayoutsBetweenClasses): Ditto
+
+
 2001-12-05  John Levon  <moz@compsoc.man.ac.uk>
 
        * lyxtext.h:
index 8e9c574c4f159e5e6337b8b507b124e0979eeabd..4990bb234d3d8bbe7e7e01e63fc93f1269efe5a3 100644 (file)
@@ -17,6 +17,7 @@
 #include "lyx_gui_misc.h"
 #include "lyxcursor.h"
 #include "gettext.h"
+#include "iterators.h"
 
 #ifdef __GNUG__
 #pragma implementation
@@ -366,16 +367,18 @@ int CutAndPaste::SwitchLayoutsBetweenClasses(textclass_type c1,
        int ret = 0;
        if (!par || c1 == c2)
                return ret;
-       
-       while (par) {
+
+       ParIterator end = ParIterator();
+       for (ParIterator it = ParIterator(par); it != end; ++it) {
+               par = *it;
                string const name = textclasslist.NameOfLayout(c1, par->layout);
                int lay = 0;
                pair<bool, layout_type> pp =
                        textclasslist.NumberOfLayout(c2, name);
                if (pp.first) {
                        lay = pp.second;
-               } else { // layout not found
-                       // use default layout "Standard" (0)
+               } else {
+                       // not found: use default layout "Standard" (0)
                        lay = 0;
                }
                par->layout = lay;
@@ -391,7 +394,6 @@ int CutAndPaste::SwitchLayoutsBetweenClasses(textclass_type c1,
                        InsetError * new_inset = new InsetError(s);
                        par->insertInset(0, new_inset);
                }
-               par = par->next();
        }
        return ret;
 }
index e94479dd049e60c8ed05430734ffe06bfaaa8e4c..86c1218e8579e919d1c7e7a8ec693fc7dcf428e3 100644 (file)
@@ -2,7 +2,7 @@
 
 #include "iterators.h"
 
-ParIterator  & ParIterator::operator++()
+ParIterator & ParIterator::operator++()
 {
        while (!positions.empty()) {
                ParPosition & p = positions.back();
@@ -16,7 +16,11 @@ ParIterator  & ParIterator::operator++()
                                return *this;
                        }
                        ++p.it;
-               }
+               } else
+                       // The following line is needed because the value of
+                       // p.it may be invalid if inset was added/removed to
+                       // the paragraph pointed by the iterator
+                       p.it = p.par->inset_iterator_begin();
 
                // Try to find the next inset that contains paragraphs
                for ( ; p.it != p.par->inset_iterator_end(); ++p.it) {