forked from qt-creator/qt-creator
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:
@@ -626,6 +626,14 @@ void DocumentContainer::drawSelection(QPainter *painter, const QRect &clip) cons
|
|||||||
painter->restore();
|
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()
|
void DocumentContainer::buildIndex()
|
||||||
{
|
{
|
||||||
m_index.elementToIndex.clear();
|
m_index.elementToIndex.clear();
|
||||||
@@ -633,10 +641,13 @@ void DocumentContainer::buildIndex()
|
|||||||
m_index.text.clear();
|
m_index.text.clear();
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
bool inBody = false;
|
||||||
litehtml::element::ptr current = firstLeaf(m_document->root(), nullptr);
|
litehtml::element::ptr current = firstLeaf(m_document->root(), nullptr);
|
||||||
while (current != m_document->root()) {
|
while (current != m_document->root()) {
|
||||||
m_index.elementToIndex.insert({current, index});
|
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;
|
litehtml::tstring text;
|
||||||
current->get_text(text);
|
current->get_text(text);
|
||||||
if (!text.empty()) {
|
if (!text.empty()) {
|
||||||
|
Reference in New Issue
Block a user