Abdelrazak Younes a écrit :
Jean-Marc Lasgouttes a écrit :
"Abdelrazak" == Abdelrazak Younes <[EMAIL PROTECTED]> writes:

Abdelrazak> Jean-Marc Lasgouttes a écrit :
bool needsUpdateCounters(Buffer const & buf, ParIterator & it) { if
(it->layout()->counter.empty()) {

Abdelrazak> Apparently, this is not a good test for enumerate (returns
Abdelrazak> true). Do you know why?

Yes, because enumerate is hardcoded to use four different counters, on
per level.

So maybe after all it is better to enumerate the cases that are not a
problem:

OK, I'll use a switch then with all the following cases. I'll send a patch soon.

Here is the patch. It took me a bit longer than I thought because I did not understand the logic in the cursor in breakParagraph(). With my former patch one call to needsUpdateCounter on next_par was enough. With the ParIterator version I need to test both current and next par in order to cover all the cases. Anyway, double-check is maybe better.

OK to apply to 1.5svn?

Maybe it is too late for 1.4.1 but please give it a test ride. There is nothing intrusive in there.

Log:
* buffer_funcs.[Ch]: new needsUpdateCounters function

* text.C:
- LyXText::breakParagraph(): test if needsUpdateCounters() is enough before a full updateCounter
 - LyXText::backspacePos0(): ditto

* text2.C:
 - LyXText::deleteEmptyParagraphMechanism(): ditto


Index: buffer_funcs.C
===================================================================
--- buffer_funcs.C      (revision 13538)
+++ buffer_funcs.C      (working copy)
@@ -503,6 +503,31 @@
 } // anon namespace
 
 
+bool needsUpdateCounters(Buffer const & buf, ParIterator & it)
+{
+       switch (it->layout()->labeltype) {
+
+       case LABEL_NO_LABEL:
+       case LABEL_MANUAL:
+       case LABEL_BIBLIO:
+       case LABEL_TOP_ENVIRONMENT:
+       case LABEL_CENTERED_TOP_ENVIRONMENT:
+       case LABEL_STATIC:
+       case LABEL_ITEMIZE:
+               setCounter(buf, it);
+               return false;
+
+       case LABEL_SENSITIVE:
+       case LABEL_COUNTER:
+       // do more things with enumerate later
+       case LABEL_ENUMERATE:
+               return true;
+
+       default:
+               return true;
+       }
+}
+
 void updateCounters(Buffer const & buf)
 {
        // start over
Index: buffer_funcs.h
===================================================================
--- buffer_funcs.h      (revision 13538)
+++ buffer_funcs.h      (working copy)
@@ -21,6 +21,7 @@
 class DocIterator;
 class ErrorList;
 class TeXErrors;
+class ParIterator;
 
 /**
  *  Loads a LyX file \c filename into \c Buffer
@@ -48,6 +49,13 @@
 std::string expandLabel(Buffer const & buf, LyXLayout_ptr const & layout,
                        bool appendix);
 
+/// updates current counter and/or label if possible.
+/**
+\retval true if a full updateCounters is required.
+\retval false if a full updateCounters is not required.
+*/
+bool needsUpdateCounters(Buffer const & buf, ParIterator & it);
+
 /// updates all counters
 void updateCounters(Buffer const &);
 
Index: text.C
===================================================================
--- text.C      (revision 13538)
+++ text.C      (working copy)
@@ -24,6 +24,7 @@
 #include "bufferparams.h"
 #include "BufferView.h"
 #include "cursor.h"
+#include "pariterator.h"
 #include "coordcache.h"
 #include "CutAndPaste.h"
 #include "debug.h"
@@ -1087,8 +1088,13 @@
        while (!pars_[next_par].empty() && pars_[next_par].isNewline(0))
                pars_[next_par].erase(0);
 
-       updateCounters(cur.buffer());
+       ParIterator current_it(cur);
+       ParIterator next_it(cur); next_it.pit() = next_par;
 
+       if (needsUpdateCounters(cur.buffer(), current_it)
+               || needsUpdateCounters(cur.buffer(), next_it))
+               updateCounters(cur.buffer());
+
        // Mark "carriage return" as inserted if change tracking:
        if (cur.buffer().params().tracking_changes) {
                cur.paragraph().setChange(cur.paragraph().size(), 
@@ -1669,7 +1675,10 @@
                                --cur.pos();
 
                // the counters may have changed
-               updateCounters(cur.buffer());
+               ParIterator par_it(cur);
+               if (needsUpdateCounters(cur.buffer(), par_it))
+                       updateCounters(cur.buffer());
+
                setCursor(cur, cur.pit(), cur.pos(), false);
        }
        return needsUpdate;
Index: text2.C
===================================================================
--- text2.C     (revision 13538)
+++ text2.C     (working copy)
@@ -1274,7 +1274,9 @@
                                cur.resetAnchor();
                        }
                }
-               updateCounters(old.buffer());
+               ParIterator par_it(old);
+               if (needsUpdateCounters(old.buffer(), par_it))
+                       updateCounters(old.buffer());
                return true;
        }
 

Reply via email to