...because if you do, you will discover the main reason why the counter array has been attached to paragraph and not to buffer:
if you change something in the middle of your buffer that affects counters, you only recompute the counters below it. This appears to be done in the routine updateCounters in text2.C. If I *additionally* apply the attached patch, which makes updateCounters always renumber the whole buffer and not the "tail" of the buffer, everything appears to work fine. I can create or remove numbered headers, and everything is renumbered correctly. Even Figures are now numbered correctly! There are pluses and minuses about this patch, though. 1) updateCounter is called from a number of locations with different row arguments (the second arg). I don't quite overview all the implications of getting rid of this argument (which we can with this patch, a plus I think). Please give it some good testing. 2) updating all counters instead of just the remaining ones requires a little bit more resources. A worthwhile trade-off? (We do a lot less copying of counters now, with buffer counters.) I think this was a premature optimization that can go now. 3) Did anybody else notice that text.C/text2.C/lyxtext.h/paragraph.[Ch]/buffer.[Ch] is a sordid mess? I don't like tiptoeing through minefields... What shall I do with this? Martin
Index: text2.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/text2.C,v retrieving revision 1.244 diff -u -p -r1.244 text2.C --- text2.C 2002/08/10 15:21:05 1.244 +++ text2.C 2002/08/11 18:14:10 @@ -1382,14 +1381,12 @@ void LyXText::setCounter(Buffer const * void LyXText::updateCounters(BufferView * bview, Row * row) const { Paragraph * par; - - if (!row) { - row = firstrow; - par = row->par(); - } else { - par = row->par()->next(); - } + row = firstrow; + par = row->par(); + + bview->buffer()->counters().reset(""); + while (par) { while (row->par() != par) row = row->next();
msg42397/pgp00000.pgp
Description: PGP signature