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
text->setCursorIntern(this, tmpcursor.par(), tmpcursor.pos());
- return a;
+ return found;
}
+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:
#include "lyx_gui_misc.h"
#include "lyxcursor.h"
#include "gettext.h"
+#include "iterators.h"
#ifdef __GNUG__
#pragma implementation
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;
InsetError * new_inset = new InsetError(s);
par->insertInset(0, new_inset);
}
- par = par->next();
}
return ret;
}
#include "iterators.h"
-ParIterator & ParIterator::operator++()
+ParIterator & ParIterator::operator++()
{
while (!positions.empty()) {
ParPosition & p = positions.back();
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) {