Help/litehtml: Fix that invisible text was found via text search

We need to explicitly restrict the index to the html body, otherwise
e.g. the title tag will be included.

Change-Id: Ic7d177deb9cc1c5ce072265669f4d921c9cb4bb1
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Eike Ziller
2019-09-26 11:29:31 +02:00
parent da0601e470
commit d3b4f06ada

View File

@@ -626,6 +626,14 @@ void DocumentContainer::drawSelection(QPainter *painter, const QRect &clip) cons
painter->restore();
}
static QString tagName(const litehtml::element::ptr &e)
{
litehtml::element::ptr current = e;
while (current && std::strlen(current->get_tagName()) == 0)
current = current->parent();
return current ? QString::fromUtf8(current->get_tagName()) : QString();
}
void DocumentContainer::buildIndex()
{
m_index.elementToIndex.clear();
@@ -633,10 +641,13 @@ void DocumentContainer::buildIndex()
m_index.text.clear();
int index = 0;
bool inBody = false;
litehtml::element::ptr current = firstLeaf(m_document->root(), nullptr);
while (current != m_document->root()) {
m_index.elementToIndex.insert({current, index});
if (current->is_visible()) {
if (!inBody)
inBody = tagName(current).toLower() == "body";
if (inBody && current->is_visible()) {
litehtml::tstring text;
current->get_text(text);
if (!text.empty()) {