Edwin Leuven a écrit :
> do others see this?
>
> recipe:
>
> ctrl-n
> ctrl-m
> a
> arrow right
> enter
> arrow up

Here is a patch that should get rid of the crash (even though I can't reproduce it). It is not the auto-label feature I promised (still in the works) but it simplify the calls to updateCounters and needUpdateCounters by merging then into a single update Labels.

OK to commit?

Abdel.

Log:
* src/buffer_funcs.[Ch]
 - updateCounters renamed to updateLabels
 - void updateLabels(Buffer const & buf,
   ParIterator & it): new convenience function
 - void updateLabels(Buffer const & buf,
   ParIterator & from, ParIterator & to): new convenience function
 - setCounter renamed to setLabel
 - bool tryToUpdateCurrentLabel(Buffer const & buf,
   ParIterator & it): new method
 - needsUpdateCounters: deleted

* src/BufferView_pimpl.C
* src/CutAndPaste.C
* src/frontends/controllers/ControlDocument.C
* src/lyxfunc.C
* src/text.C
* src/text2.C
* src/text3.C
 - fixed the calls to updateLabels


Index: src/buffer_funcs.C
===================================================================
--- src/buffer_funcs.C  (revision 13684)
+++ src/buffer_funcs.C  (working copy)
@@ -346,8 +346,8 @@
 }
 
 
-// set the counter of a paragraph. This includes the labels
-void setCounter(Buffer const & buf, ParIterator & it)
+// set the label of a paragraph. This includes the counters
+void setLabel(Buffer const & buf, ParIterator & it)
 {
        Paragraph & par = *it;
        BufferParams const & bufparams = buf.params();
@@ -505,8 +505,12 @@
 } // anon namespace
 
 
-bool needsUpdateCounters(Buffer const & buf, ParIterator & it)
+bool tryToUpdateCurrentLabel(Buffer const & buf, 
+       ParIterator & it)       
 {
+    if (it == par_iterator_end(buf.inset()))
+        return true;
+
        switch (it->layout()->labeltype) {
 
        case LABEL_NO_LABEL:
@@ -516,21 +520,48 @@
        case LABEL_CENTERED_TOP_ENVIRONMENT:
        case LABEL_STATIC:
        case LABEL_ITEMIZE:
-               setCounter(buf, it);
-               return false;
+               setLabel(buf, it);
+               return true;
 
        case LABEL_SENSITIVE:
        case LABEL_COUNTER:
        // do more things with enumerate later
        case LABEL_ENUMERATE:
-               return true;
+               return false;
        }
+
+       // This is dead code which get rid of a warning:
+       return true;
 }
 
 
-void updateCounters(Buffer const & buf)
+void updateLabels(Buffer const & buf, 
+       ParIterator & from, ParIterator & to)
 {
-       // start over
+       for (ParIterator it = from; it != to; ++it) {
+               if (it.pit() > it.lastpit())
+                       return;
+               if (!tryToUpdateCurrentLabel(buf, it)) {
+                       updateLabels(buf);
+                       return;
+               }
+       }
+}
+
+
+void updateLabels(Buffer const & buf, 
+       ParIterator & iter)
+{
+       if (tryToUpdateCurrentLabel(buf, iter))
+               return;
+
+       updateLabels(buf);
+}
+
+
+void updateLabels(Buffer const & buf)
+{
+       // start over the counters
        buf.params().getLyXTextClass().counters().reset();
 
        for (ParIterator it = par_iterator_begin(buf.inset()); it; ++it) {
@@ -543,7 +574,7 @@
                        it->params().depth(0);
 
                // set the counter for this paragraph
-               setCounter(buf, it);
+               setLabel(buf, it);
        }
 }
 
Index: src/buffer_funcs.h
===================================================================
--- src/buffer_funcs.h  (revision 13684)
+++ src/buffer_funcs.h  (working copy)
@@ -49,15 +49,21 @@
 std::string expandLabel(Buffer const & buf, LyXLayout_ptr const & layout,
                        bool appendix);
 
-/// updates current counter and/or label if possible.
+
+/// update labels at "iter".
 /**
-\retval true if a full updateCounters is required.
-\retval false if a full updateCounters is not required.
+A full updateLabels(Buffer const &) will be called if not possible.
 */
-bool needsUpdateCounters(Buffer const & buf, ParIterator & it);
+void updateLabels(Buffer const & buf, ParIterator & it);
 
+/// update labels between "from" and "to" if possible.
+/**
+A full updateLabels(Buffer const &) will be called if not possible.
+*/
+void updateLabels(Buffer const & buf,
+       ParIterator & from, ParIterator & to);
+
 /// updates all counters
-void updateCounters(Buffer const &);
+void updateLabels(Buffer const &);
 
-
 #endif // BUFFER_FUNCS_H
Index: src/BufferView_pimpl.C
===================================================================
--- src/BufferView_pimpl.C      (revision 13684)
+++ src/BufferView_pimpl.C      (working copy)
@@ -1236,7 +1236,7 @@
                lyx::toc::outline(op, buffer_, cursor_.pit());
                bv_->text()->setCursor(cursor_, cursor_.pit(), 0);
                buffer_->markDirty();
-               updateCounters(*buffer_);
+               updateLabels(*buffer_);
                update();
        }
 
Index: src/CutAndPaste.C
===================================================================
--- src/CutAndPaste.C   (revision 13684)
+++ src/CutAndPaste.C   (working copy)
@@ -516,7 +516,7 @@
 
                // need a valid cursor. (Lgb)
                cur.clearSelection();
-               updateCounters(cur.buffer());
+               updateLabels(cur.buffer());
 
                // tell tabular that a recent copy happened
                dirtyTabularStack(false);
@@ -610,7 +610,7 @@
                                             parlist, textclass,
                                             el);
                bufferErrors(cur.buffer(), el);
-               updateCounters(cur.buffer());
+               updateLabels(cur.buffer());
                cur.clearSelection();
                text->setCursor(cur, ppp.first, ppp.second);
        }
Index: src/frontends/controllers/ControlDocument.C
===================================================================
--- src/frontends/controllers/ControlDocument.C (revision 13684)
+++ src/frontends/controllers/ControlDocument.C (working copy)
@@ -104,7 +104,7 @@
 
        // redo the numbering if necessary
        if (new_secnumdepth != old_secnumdepth)
-               updateCounters(kernel().buffer());
+               updateLabels(kernel().buffer());
 
        // Generate the colours requested by each new branch.
        BranchList & branchlist = params().branchlist();
Index: src/lyxfunc.C
===================================================================
--- src/lyxfunc.C       (revision 13684)
+++ src/lyxfunc.C       (working copy)
@@ -1564,7 +1564,7 @@
                        
view()->setCursor(backcur.asDocIterator(&(buffer->inset())));
                        bufferErrors(*buffer, el);
                        view()->showErrorList(_("Class switch"));
-                       updateCounters(*buffer);
+                       updateLabels(*buffer);
                        update = true;
                        break;
                }
Index: src/text.C
===================================================================
--- src/text.C  (revision 13684)
+++ src/text.C  (working copy)
@@ -1090,11 +1090,11 @@
                pars_[next_par].erase(0);
 
        ParIterator current_it(cur);
-       ParIterator next_it(cur); next_it.pit() = next_par;
+       ParIterator last_it(cur);
+       ++last_it;
+       ++last_it;
 
-       if (needsUpdateCounters(cur.buffer(), current_it)
-               || needsUpdateCounters(cur.buffer(), next_it))
-               updateCounters(cur.buffer());
+       updateLabels(cur.buffer(), current_it, last_it);
 
        // Mark "carriage return" as inserted if change tracking:
        if (cur.buffer().params().tracking_changes) {
@@ -1677,8 +1677,7 @@
 
                // the counters may have changed
                ParIterator par_it(cur);
-               if (needsUpdateCounters(cur.buffer(), par_it))
-                       updateCounters(cur.buffer());
+               updateLabels(cur.buffer(), par_it);
 
                setCursor(cur, cur.pit(), cur.pos(), false);
        }
Index: src/text2.C
===================================================================
--- src/text2.C (revision 13684)
+++ src/text2.C (working copy)
@@ -90,7 +90,7 @@
                pars_[pit].rows().clear();
 
        current_font = getFont(pars_[0], 0);
-       updateCounters(*bv->buffer());
+       updateLabels(*bv->buffer());
 }
 
 
@@ -358,7 +358,7 @@
        pit_type undopit = undoSpan(end - 1);
        recUndo(start, undopit - 1);
        setLayout(start, end, layout);
-       updateCounters(cur.buffer());
+       updateLabels(cur.buffer());
 }
 
 
@@ -419,7 +419,7 @@
        }
        // this handles the counter labels, and also fixes up
        // depth values for follow-on (child) paragraphs
-       updateCounters(cur.buffer());
+       updateLabels(cur.buffer());
 }
 
 
@@ -1275,8 +1275,7 @@
                        }
                }
                ParIterator par_it(old);
-               if (needsUpdateCounters(old.buffer(), par_it))
-                       updateCounters(old.buffer());
+               updateLabels(old.buffer(), par_it);
                return true;
        }
 
Index: src/text3.C
===================================================================
--- src/text3.C (revision 13684)
+++ src/text3.C (working copy)
@@ -342,7 +342,7 @@
                par.params().startOfAppendix(start);
 
                // we can set the refreshing parameters now
-               updateCounters(cur.buffer());
+               updateLabels(cur.buffer());
                break;
        }
 

Reply via email to