Attached patch fixes a crach when changing a font over a range
containing a nested math inset.

I am not sure whether nested insets should be immune to font changes in
general. It is the right thing for e.g. footnotes, but I am not sure
about the general case.

I any case, this fixes a crash, so someone please commit.

Andre'
--- dociterator.h.orig  2005-02-13 17:48:38.000000000 +0100
+++ dociterator.h       2005-02-13 17:49:32.000000000 +0100
@@ -177,7 +177,9 @@
        //
        // elementary moving
        //
-       /// move on one logical position
+       /// move on one logical position, do not descend into nested insets
+       void forwardPosNoDescend();
+       /// move on one logical position, descend into nested insets
        void forwardPos();
        /// move on one physical character or inset
        void forwardChar();
--- dociterator.C.orig  2004-10-23 12:58:07.000000000 +0200
+++ dociterator.C       2005-02-13 17:50:05.000000000 +0100
@@ -132,6 +138,8 @@
 
 Paragraph & DocIterator::paragraph()
 {
+       if (!inTexted()) 
+               lyxerr << *this << endl;
        BOOST_ASSERT(inTexted());
        return top().paragraph();
 }
@@ -329,11 +338,46 @@
        // otherwise leave inset and jump over inset as a whole
        pop_back();
        // 'top' is invalid now...
        if (!empty())
                ++top().pos();
 }
 
 
+void DocIterator::forwardPosNoDescend()
+{
+       CursorSlice & tip = top();
+       pos_type const lastp = lastpos();
+
+       //  move on one position if possible
+       if (tip.pos() < lastp) {
+               //lyxerr << "... next pos" << endl;
+               ++tip.pos();
+               return;
+       }
+       //lyxerr << "... no next pos" << endl;
+
+       // otherwise move on one paragraph if possible
+       if (tip.pit() < lastpit()) {
+               //lyxerr << "... next par" << endl;
+               ++tip.pit();
+               tip.pos() = 0;
+               return;
+       }
+       //lyxerr << "... no next pit" << endl;
+
+       // otherwise try to move on one cell if possible
+       if (tip.idx() < lastidx()) {
+               //lyxerr << "... next idx" << endl;
+               ++tip.idx();
+               tip.pit() = 0;
+               tip.pos() = 0;
+               return;
+       }
+       //lyxerr << "... no next idx" << endl;
+
+       // otherwise we can't move on
+}
+
 void DocIterator::forwardPar()
 {
        forwardPos();
--- text2.C.orig        2005-02-13 17:52:54.000000000 +0100
+++ text2.C     2005-02-13 17:53:02.000000000 +0100
@@ -440,7 +440,9 @@
 
        // Don't use forwardChar here as ditend might have
        // pos() == lastpos() and forwardChar would miss it.
-       for (; dit != ditend; dit.forwardPos()) {
+       // Can't use forwardPos either as this descends into
+       // nested insets. 
+       for (; dit != ditend; dit.forwardPosNoDescend()) {
                if (dit.pos() != dit.lastpos()) {
                        LyXFont f = getFont(dit.paragraph(), dit.pos());
                        f.update(font, params.language, toggleall);

Reply via email to