mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15:24:05 +00:00
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:
parent
15cb327bbd
commit
585866f92a
|
@ -453,26 +453,8 @@ void FullTextSearchDialog::itemClicked( const QModelIndex & idx )
|
||||||
auto searchText = ui.searchLine->text();
|
auto searchText = ui.searchLine->text();
|
||||||
searchText.replace( RX::Ftx::tokenBoundary, " " );
|
searchText.replace( RX::Ftx::tokenBoundary, " " );
|
||||||
|
|
||||||
auto it = RX::Ftx::token.globalMatch( searchText );
|
if ( !searchText.isEmpty() ) {
|
||||||
QString firstAvailbeItem;
|
reg = QRegularExpression( searchText, QRegularExpression::CaseInsensitiveOption );
|
||||||
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 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
emit showTranslationFor( headword, results[ idx.row() ].dictIDs, reg, false );
|
emit showTranslationFor( headword, results[ idx.row() ].dictIDs, reg, false );
|
||||||
|
|
|
@ -2125,8 +2125,8 @@ void ArticleView::highlightFTSResults()
|
||||||
|
|
||||||
QString script = QString(
|
QString script = QString(
|
||||||
"var context = document.querySelector(\"body\");\n"
|
"var context = document.querySelector(\"body\");\n"
|
||||||
"var instance = new Mark(context);\n"
|
"var instance = new Mark(context);\n instance.unmark();\n"
|
||||||
"instance.mark(\"%1\",{\"accuracy\": \"exactly\"});" )
|
"instance.mark(\"%1\");" )
|
||||||
.arg( regString );
|
.arg( regString );
|
||||||
|
|
||||||
webview->page()->runJavaScript( script );
|
webview->page()->runJavaScript( script );
|
||||||
|
|
Loading…
Reference in a new issue