mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-05 13:26:21 +00:00
Properly search for relevant TocItem. Now works fine with sections inside insets.
* DocIterator - new comparison operators: <, > and <= (Courtesy of JMarc) * TocBackend::item() use above <= operator instead of crude pit() comparison. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18349 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
f653540961
commit
6277ba63ab
@ -553,6 +553,28 @@ std::ostream & operator<<(std::ostream & os, DocIterator const & dit)
|
||||
}
|
||||
|
||||
|
||||
bool operator<(DocIterator const & p, DocIterator const & q)
|
||||
{
|
||||
size_t depth = std::min(p.depth(), q.depth());
|
||||
for (size_t i = 0 ; i < depth ; ++i) {
|
||||
if (p[i] != q[i])
|
||||
return p[i] < q[i];
|
||||
}
|
||||
return p.depth() < q.depth();
|
||||
}
|
||||
|
||||
|
||||
bool operator>(DocIterator const & p, DocIterator const & q)
|
||||
{
|
||||
return q < p;
|
||||
}
|
||||
|
||||
|
||||
bool operator<=(DocIterator const & p, DocIterator const & q)
|
||||
{
|
||||
return !(q < p);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////
|
||||
|
||||
|
@ -213,6 +213,9 @@ public:
|
||||
operator<<(std::ostream & os, DocIterator const & cur);
|
||||
///
|
||||
friend bool operator==(DocIterator const &, DocIterator const &);
|
||||
friend bool operator<(DocIterator const &, DocIterator const &);
|
||||
friend bool operator>(DocIterator const &, DocIterator const &);
|
||||
friend bool operator<=(DocIterator const &, DocIterator const &);
|
||||
///
|
||||
friend class StableDocIterator;
|
||||
//protected:
|
||||
|
@ -242,19 +242,9 @@ TocIterator const TocBackend::item(
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user