gui: PreviewGenerator*: Fallback to partial highlighting if no whole word match
这个提交包含在:
父节点
5a47f5949f
当前提交
2df273dee3
@ -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);
|
||||
|
@ -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;
|
||||
|
正在加载...
在新工单中引用
屏蔽一个用户