fix: fts search ,highlight mark (#1621)

* fix:mark the searched terms

* fix:mark the searched terms

* fix:mark the searched terms
This commit is contained in:
xiaoyifang 2024-06-27 18:00:06 +08:00 committed by GitHub
parent 15cb327bbd
commit 585866f92a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 22 deletions

View file

@ -453,26 +453,8 @@ void FullTextSearchDialog::itemClicked( const QModelIndex & idx )
auto searchText = ui.searchLine->text();
searchText.replace( RX::Ftx::tokenBoundary, " " );
auto it = RX::Ftx::token.globalMatch( searchText );
QString firstAvailbeItem;
while ( it.hasNext() ) {
QRegularExpressionMatch match = it.next();
auto p = match.captured();
if ( p.startsWith( '-' ) )
continue;
//the searched text should be like "term".remove enclosed double quotation marks.
if ( p.startsWith( "\"" ) ) {
p.remove( "\"" );
}
firstAvailbeItem = p;
break;
}
if ( !firstAvailbeItem.isEmpty() ) {
reg = QRegularExpression( firstAvailbeItem, QRegularExpression::CaseInsensitiveOption );
if ( !searchText.isEmpty() ) {
reg = QRegularExpression( searchText, QRegularExpression::CaseInsensitiveOption );
}
emit showTranslationFor( headword, results[ idx.row() ].dictIDs, reg, false );

View file

@ -2125,8 +2125,8 @@ void ArticleView::highlightFTSResults()
QString script = QString(
"var context = document.querySelector(\"body\");\n"
"var instance = new Mark(context);\n"
"instance.mark(\"%1\",{\"accuracy\": \"exactly\"});" )
"var instance = new Mark(context);\n instance.unmark();\n"
"instance.mark(\"%1\");" )
.arg( regString );
webview->page()->runJavaScript( script );