Abdelrazak Younes wrote:
Ozgur Ugras BARAN wrote:
This small patch prevents LOF, LOT always selects the last entry.
LOT/LOF still does not follow the cursor, yet, but for this, we need
serious update in TocBackend.

Not that much work IMO. The problem is the way we search for the toc item is very crude. Look at the comment in TocBackend::item():

// A good solution for Items inside insets would be to do:
//
//if (std::distance(it->par_it_, current) <= 0)
//    return it;
//
// But for an unknown reason, std::distance(current, it->par_it_) always
// returns  a positive value and std::distance(it->par_it_, current)
// takes forever...
// So for now, we do:
if (it->par_it_.pit() <= par_it_text.pit())
    return it;

This is not correct and will work only for top-level items. So if someone could implement an <= operator for ParConstIterator, that would solve our problem. Jean-Marc, Andre, your the experts in this field, could you implement this:

bool operator<=(ParConstIterator const &, ParConstIterator const &);

I've done it but I am not sure I got it right. JMarc?

Abdel.

Index: DocIterator.cpp
===================================================================
--- DocIterator.cpp     (revision 18303)
+++ DocIterator.cpp     (working copy)
@@ -553,7 +553,20 @@
 }
 
 
+bool operator<=(DocIterator const & di1, DocIterator const & di2)
+{
+       size_t const n1 = di1.slices_.size();
+       size_t const n2 = di2.slices_.size();
+       for (size_t i = 0 ; i < n1; ++i) {
+               if (i >= n2)
+                       return false;
+               if (di1.slices_[i].pit() <= di2.slices_[i].pit())
+                       return true;
+       }
+       return false;
+}
 
+
 ///////////////////////////////////////////////////////
 
 StableDocIterator::StableDocIterator(DocIterator const & dit)
Index: DocIterator.h
===================================================================
--- DocIterator.h       (revision 18303)
+++ DocIterator.h       (working copy)
@@ -214,6 +214,8 @@
        ///
        friend bool operator==(DocIterator const &, DocIterator const &);
        ///
+       friend bool operator<=(DocIterator const &, DocIterator const &);
+       ///
        friend class StableDocIterator;
 //protected:
        ///
@@ -271,6 +273,9 @@
 }
 
 
+bool operator<=(DocIterator const & di1, DocIterator const & di2);
+
+
 // The difference to a ('non stable') DocIterator is the removed
 // (overwritten by 0...) part of the CursorSlice data items. So this thing
 // is suitable for external storage, but not for iteration as such.
Index: TocBackend.cpp
===================================================================
--- TocBackend.cpp      (revision 18303)
+++ TocBackend.cpp      (working copy)
@@ -240,19 +240,9 @@
                while (par_it_text.inMathed())
                        par_it_text.backwardPos();
 
-       for (; it != last; --it) {
-               
-               // A good solution for Items inside insets would be to do:
-               //
-               //if (std::distance(it->par_it_, current) <= 0)
-               //      return it;
-               //
-               // But for an unknown reason, std::distance(current, 
it->par_it_) always
-               // returns  a positive value and std::distance(it->par_it_, 
current) takes forever...
-               // So for now, we do:
-               if (it->par_it_.pit() <= par_it_text.pit())
+       for (; it != last; --it)
+               if (it->par_it_ <= par_it_text)
                        return it;
-       }
 
        // We are before the first Toc Item:
        return last;

Reply via email to