Skip to content

Commit

Permalink
fix: fts search ,highlight mark (#1621)
Browse files Browse the repository at this point in the history
* fix:mark the searched terms

* fix:mark the searched terms

* fix:mark the searched terms
  • Loading branch information
xiaoyifang authored Jun 27, 2024
1 parent 15cb327 commit 585866f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 22 deletions.
22 changes: 2 additions & 20 deletions src/fulltextsearch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
4 changes: 2 additions & 2 deletions src/ui/articleview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down

0 comments on commit 585866f

Please sign in to comment.