gui: PreviewGenerator*: Fallback to partial highlighting if no whole word match

Šī revīzija ir iekļauta:
Albert S. 2022-08-28 12:44:42 +02:00
vecāks 5a47f5949f
revīzija 2df273dee3
2 mainīti faili ar 22 papildinājumiem un 3 dzēšanām

Parādīt failu

@ -49,6 +49,10 @@ QSharedPointer<PreviewResult> PreviewGeneratorPdf::generate(RenderConfig config,
{
QList<QRectF> rects =
pdfPage->search(word, Poppler::Page::SearchFlag::IgnoreCase | Poppler::Page::SearchFlag::WholeWords);
if(rects.empty())
{
rects = pdfPage->search(word, Poppler::Page::SearchFlag::IgnoreCase);
}
for(QRectF &rect : rects)
{
QPainter painter(&img);

Parādīt failu

@ -103,10 +103,25 @@ QString PreviewGeneratorPlainText::generateLineBasedPreviewText(QTextStream &in,
for(QString &word : config.wordsToHighlight)
{
QRegularExpression searchRegex("\\b" + word + "\\b");
if(line.contains(searchRegex))
bool containsRegex = line.contains(searchRegex);
bool contains = false;
if(!containsRegex)
{
contains = line.contains(word, Qt::CaseInsensitive);
}
if(containsRegex || contains)
{
currentSnippet.wordCountMap[word] = currentSnippet.wordCountMap.value(word, 0) + 1;
line.replace(searchRegex, "<span style=\"background-color: yellow;\">" + word + "</span>");
QString replacementString = "<span style=\"background-color: yellow;\">" + word + "</span>";
if(containsRegex)
{
line.replace(searchRegex, replacementString);
}
else
{
line.replace(word, replacementString, Qt::CaseInsensitive);
}
++foundWordsCount;
}
}
@ -143,7 +158,7 @@ QString PreviewGeneratorPlainText::generateLineBasedPreviewText(QTextStream &in,
}
for(QString &word : config.wordsToHighlight)
{
if(currentLine.contains(QRegularExpression("\\b" + word + "\\b")))
if(currentLine.contains(word, Qt::CaseInsensitive))
{
matched = true;
break;