From 48d9d01a826eb9f1c1e7c62edb664ec97f6a6e8d Mon Sep 17 00:00:00 2001 From: Thibaut Cuvelier Date: Sun, 20 Nov 2022 02:02:13 +0100 Subject: [PATCH] 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). --- src/insets/InsetIndex.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/insets/InsetIndex.cpp b/src/insets/InsetIndex.cpp index 3788a360f5..bd38cf506f 100644 --- a/src/insets/InsetIndex.cpp +++ b/src/insets/InsetIndex.cpp @@ -1679,12 +1679,17 @@ 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. - child->entries.emplace_back(entry); + if (!entry.terms()[depth].empty()) + child->entries.emplace_back(entry); return; } else { insertIntoNode(entry, child, depth + 1); @@ -1718,6 +1723,12 @@ IndexNode* buildIndexTree(vector& 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); }