InsetIndex: when building the IndexNode tree, ignore IndexEntry when empty

The previous code always considered it had at least one term (an assumption that is wrong at least for doc/de/Math.lyx).
This commit is contained in:
Thibaut Cuvelier 2022-11-20 02:02:13 +01:00
parent 77f0fbdc9a
commit 48d9d01a82

View File

@ -1679,11 +1679,16 @@ docstring termAtLevel(const IndexNode* node, unsigned depth)
void insertIntoNode(const IndexEntry& entry, IndexNode* node, unsigned depth = 0)
{
// Do not insert empty entries.
if (entry.terms().empty())
return;
// depth == 0 is for the root, not yet the index, hence the increase when going to vector size.
for (IndexNode* child : node->children) {
if (entry.terms()[depth] == termAtLevel(child, depth)) {
if (depth + 1 == entry.terms().size()) { // == child.entries.begin()->terms().size()
// All term entries match: it's an entry.
if (!entry.terms()[depth].empty())
child->entries.emplace_back(entry);
return;
} else {
@ -1718,6 +1723,12 @@ IndexNode* buildIndexTree(vector<IndexEntry>& entries)
// as children.
auto* index_root = new IndexNode{{}, {}};
for (const IndexEntry& entry : entries) {
std::cout << "Entry: " << std::endl;
std::cout << entry.terms().empty() << std::endl;
std::cout << entry.terms().size() << std::endl;
for (const docstring& d : entry.terms()) {
std::cout << "\"" << to_utf8(d) << "\"" << std::endl;
}
insertIntoNode(entry, index_root);
}