mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14: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();
|
||||
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 );
|
||||
|
|
|
@ -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 );
|
||||
|
|
Loading…
Reference in a new issue