On Wed, 5 Jun 2002, Allan Rae wrote:

> It's not quite as simple as errors after a newline not being removed.
> Some are, but those in the overly long testcase aren't.  I will
> investigate this weekend.

I've figured it out.  This change:

2002-03-13  Lars Gullik Bjønnes  <[EMAIL PROTECTED]>

        * paragraph.C: change several algorithm to be more appripriate for
        the problem domain. This is lookip in FontList and in the InsetList.

modified Paragraph::InsetIterator(pos) so that it no longer returned
an inset_iterator with (it.pos >= pos) but now only returns one if
(it.pos == pos).  The net result being that removeAutoInsets() can't
iterate through the inset list deleting auto-insets as it goes by
simply calling InsetIterator(pos) -- unless the insets are
consecutive like they very often are.

Three possible solutions:
1.  Fix InsetIterator(pos)
2.  Add nextInsetIterator(pos) with these semantics
3.  Workaround InsetIterator() in removeAutoInsets()

I picked option 2 since there may be other places that would also
expect the next nearest inset to be returned rather than
insetlist.end() when an inset doesn't exist at pos.  Of course that
will only come as paragraph.C is cleaned up to use these helper
functions instead of implementing it locally in every second function.

Any particular reason why InsetIterator() is capitalised?  Is it
because someone was thinking it looks/acts like a constructor?
André?  (cvs annotate blames you for the name)

Anyway, I've attached a patch against 1.2.1cvs -- it should apply and
work with 1.3.0cvs but I can't compile that tree at present
(automake-1.4 not acceptable and upgrading is a low priority).

JMarc you will certainly want this fix (or something similar).



Herbert's report has also led to discovering another bug (haven't
checked Bugzilla yet):
        Error insets are inserted in the wrong row of non-default
        document language text -- inserted one row later.

Allan. (ARRae)
? buildtree
Index: src/BufferView2.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView2.C,v
retrieving revision 1.126.2.1
diff -u -p -r1.126.2.1 BufferView2.C
--- src/BufferView2.C   15 May 2002 23:50:47 -0000      1.126.2.1
+++ src/BufferView2.C   9 Jun 2002 05:58:55 -0000
@@ -200,7 +200,7 @@ bool BufferView::removeAutoInsets()
                                par->erase(pos);
                                // We just invalidated par's inset iterators so
                                // we get the next valid iterator position
-                               pit = par->InsetIterator(pos);
+                               pit = par->nextInsetIterator(pos);
                                // and ensure we have a valid end iterator.
                                pend = par->inset_iterator_end();
 
Index: src/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/ChangeLog,v
retrieving revision 1.713.2.10
diff -u -p -r1.713.2.10 ChangeLog
--- src/ChangeLog       6 Jun 2002 15:14:20 -0000       1.713.2.10
+++ src/ChangeLog       9 Jun 2002 05:58:56 -0000
@@ -1,3 +1,10 @@
+2002-06-09  Allan Rae  <[EMAIL PROTECTED]>
+
+       * paragraph.[hC] (nextInsetIterator): new function
+       * BufferView2.C (removeAutoInsets): Fix bug #432 which was introduced
+       when the paragraph iterator algorithms were rewritten.  Added and use
+       a new iterator function with required semantics.
+
 2002-05-31  John Levon  <[EMAIL PROTECTED]>
 
        * lyxvc.C: fix bug 416 (make sure buffer is saved before
Index: src/paragraph.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph.C,v
retrieving revision 1.205
diff -u -p -r1.205 paragraph.C
--- src/paragraph.C     14 May 2002 09:40:53 -0000      1.205
+++ src/paragraph.C     9 Jun 2002 05:58:56 -0000
@@ -1229,6 +1229,20 @@ Paragraph::InsetIterator(pos_type pos)
 }
 
 
+Paragraph::inset_iterator
+Paragraph::nextInsetIterator(pos_type pos)
+{
+       InsetList::iterator it = insetlist.begin();
+       InsetList::iterator end = insetlist.end();
+       for (; it != end; ++it) {
+               if (it->pos >= pos)
+                       break;
+       }
+
+       return inset_iterator(it);
+}
+
+
 // returns -1 if inset not found
 int Paragraph::getPositionOfInset(Inset const * inset) const
 {
Index: src/paragraph.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph.h,v
retrieving revision 1.31
diff -u -p -r1.31 paragraph.h
--- src/paragraph.h     21 Mar 2002 17:25:18 -0000      1.31
+++ src/paragraph.h     9 Jun 2002 05:58:56 -0000
@@ -395,8 +395,10 @@ public:
        inset_iterator inset_iterator_begin();
        ///
        inset_iterator inset_iterator_end();
-       ///
+       /// returns inset iterator of inset at pos
        inset_iterator InsetIterator(lyx::pos_type pos);
+       /// returns inset iterator of the first inset at or after pos
+       inset_iterator nextInsetIterator(lyx::pos_type pos);
 
 private:
        /// if anything uses this we don't want it to.

Reply via email to