It works fine (as far as I can judge after 2 minutes testing). I added some comments and pulled apart the loop to make the control flow easier. Alfredo, can you check please? I would be happy if we could get rid of the signals finally like this.

Stefan


Index: lyx-devel/src/CursorSlice.cpp
===================================================================
--- lyx-devel.orig/src/CursorSlice.cpp 2007-06-02 11:24:26.000000000 +0200
+++ lyx-devel/src/CursorSlice.cpp       2007-06-09 12:11:13.000000000 +0200
@@ -42,10 +42,6 @@
        : inset_(&p), idx_(0), pit_(0), pos_(0)
{
        BOOST_ASSERT(inset_);
-       boost::signal<void()> * destroyed_signal = inset_->destroyedSignal();
-       if (destroyed_signal)
-               inset_connection_ = destroyed_signal->connect(
-                       boost::bind(&CursorSlice::invalidate, this));
}
@@ -55,22 +51,12 @@
}
-CursorSlice::~CursorSlice()
-{
-       inset_connection_.disconnect();
-}
-
-
CursorSlice & CursorSlice::operator=(CursorSlice const & cs)
{
        inset_ = cs.inset_;
        idx_ = cs.idx_;
        pit_ = cs.pit_;
        pos_ = cs.pos_;
-       if (inset_ && inset_->destroyedSignal()) {
-               inset_connection_ = inset_->destroyedSignal()->connect(
-                       boost::bind(&CursorSlice::invalidate, this));
-       }
        return *this;
}
@@ -112,6 +98,14 @@
}
+pit_type CursorSlice::lastpit() const
+{
+       if (inset().inMathed())
+               return 0;
+       return text()->paragraphs().size() - 1;
+}
+
+
CursorSlice::row_type CursorSlice::row() const
{
        BOOST_ASSERT(asInsetMath());
Index: lyx-devel/src/CursorSlice.h
===================================================================
--- lyx-devel.orig/src/CursorSlice.h    2007-06-02 11:24:26.000000000 +0200
+++ lyx-devel/src/CursorSlice.h 2007-06-09 12:12:17.000000000 +0200
@@ -41,7 +41,7 @@
// that of MathData and Text should vanish. They are conceptually the
// same (now...)
-class CursorSlice : public boost::signals::trackable {
+class CursorSlice {
public:
        /// Those needs inset_ access.
        ///@{
@@ -63,8 +63,6 @@
        ///
        explicit CursorSlice(Inset &);
        ///
-       virtual ~CursorSlice();
-       ///
        CursorSlice & operator=(CursorSlice const &);
        ///
        bool isValid() const;
@@ -81,6 +79,8 @@
        pit_type pit() const { return pit_; }
        /// set the offset of the paragraph this cursor is in
        pit_type & pit() { return pit_; }
+       /// return the last paragraph offset this cursor is in
+       pit_type lastpit() const;
        /// increments the paragraph this cursor is in
        void incrementPar();
        /// decrements the paragraph this cursor is in
@@ -158,8 +158,6 @@
        bool pit_valid_;
        /// position in this cell
        pos_type pos_;
-       /// connection to referred \c inset_ destruction signal.
-       boost::signals::connection inset_connection_;
};
/// test for equality
Index: lyx-devel/src/DocIterator.cpp
===================================================================
--- lyx-devel.orig/src/DocIterator.cpp 2007-06-08 22:20:09.000000000 +0200
+++ lyx-devel/src/DocIterator.cpp       2007-06-09 12:44:07.000000000 +0200
@@ -4,6 +4,7 @@
  * Licence details can be found in the file COPYING.
  *
  * \author André Pönitz
+ * \author Alfredo Braunstein
  *
  * Full author contact details are available in file CREDITS.
  */
@@ -560,53 +561,55 @@
bool DocIterator::fixIfBroken()
{
-       bool fixed = false;
-
-       for (size_t i = slices_.size() - 1; i != 0; --i)
-               if (!slices_[i].isValid()) {
-                       pop_back();
-                       fixed = true;
+       // Go through the slice stack from the bottom.
+       // Check that all coordinates (idx, pit, pos) are correct and
+       // that the inset is the one which is claimed to be there
+       Inset * inset = &slices_[0].inset();
+       size_t i = 0;
+       size_t n = slices_.size();
+       for (; i != n; ++i) {
+               CursorSlice & cs = slices_[i];
+               if (&cs.inset() != inset) {
+                       // the whole slice is wrong, chop off this as well
+                       --i;
+                       LYXERR(Debug::DEBUG) << "fixIfBroken(): inset changed" 
<< endl;
+                       break;
+               } else if (cs.idx() > cs.lastidx()) {
+                       cs.idx() = cs.lastidx();
+                       cs.pit() = cs.lastpit();
+                       cs.pos() = cs.lastpos();
+                       LYXERR(Debug::DEBUG) << "fixIfBroken(): idx fixed" << 
endl;
+                       break;
+               } else if (cs.pit() > cs.lastpit()) {
+                       cs.pit() = cs.lastpit();
+                       cs.pos() = cs.lastpos();
+                       LYXERR(Debug::DEBUG) << "fixIfBroken(): pit fixed" << 
endl;
+                       break;
+               } else if (cs.pos() > cs.lastpos()) {
+                       cs.pos() = cs.lastpos();
+                       LYXERR(Debug::DEBUG) << "fixIfBroken(): pos fixed" << 
endl;
+                       break;
+               } else if (i != n - 1 && cs.pos() != cs.lastpos()) {
+                       // get inset which is supposed to be in the next slice
+                       if (cs.inset().inMathed())
+                               inset = (cs.cell().begin() + 
cs.pos())->nucleus();
+                       else if (cs.paragraph().isInset(cs.pos()))
+                               inset = cs.paragraph().getInset(cs.pos());
+                       else {
+                               // there are slices left, so there must be 
another inset
+                               break;
+                       }
                }
-
-       // The top level CursorSlice should always be valid.
-       BOOST_ASSERT(slices_[0].isValid());
-
-       if (idx() > lastidx()) {
-               lyxerr << "wrong idx " << idx()
-                       << ", max is " << lastidx()
-                       << " at level " << depth()
-                       << ". Trying to correct this."  << endl;
-               lyxerr << "old: " << *this << endl;
-               for (size_t i = idx(); i != lastidx(); --i)
-                       pop_back();
-               idx() = lastidx();
-               pit() = lastpit();
-               pos() = lastpos();
-               fixed = true;
-       }
-       else if (pit() > lastpit()) {
-               lyxerr << "wrong pit " << pit()
-                       << ", max is " << lastpit()
-                       << " at level " << depth()
-                       << ". Trying to correct this."  << endl;
-               lyxerr << "old: " << *this << endl;
-               pit() = lastpit();
-               pos() = 0;
-               fixed = true;
-       }
-       else if (pos() > lastpos()) {
-               lyxerr << "wrong pos " << pos()
-                       << ", max is " << lastpos()
-                       << " at level " << depth()
-                       << ". Trying to correct this."  << endl;
-               lyxerr << "old: " << *this << endl;
-               pos() = lastpos();
-               fixed = true;
-       }
-       if (fixed) {
-               lyxerr << "new: " << *this << endl;
        }
-       return fixed;
+
+       // Did we make it through the whole slice stack? Otherwise there
+       // was a problem at slice i, and we have to chop off above
+       if (i < n) {
+ LYXERR(Debug::DEBUG) << "fixIfBroken(): cursor chopped at " << i << endl;
+               resize(i + 1);
+               return true;
+       } else
+               return false;
}


Attachment: fixifbroken2.patch
Description: Binary data



Attachment: PGP.sig
Description: Signierter Teil der Nachricht

Reply via email to