From 585866f92a5ecc93d2dbd416d37b7bebc320bab0 Mon Sep 17 00:00:00 2001 From: xiaoyifang <105986+xiaoyifang@users.noreply.github.com> Date: Thu, 27 Jun 2024 18:00:06 +0800 Subject: [PATCH] fix: fts search ,highlight mark (#1621) * fix:mark the searched terms * fix:mark the searched terms * fix:mark the searched terms --- src/fulltextsearch.cc | 22 ++-------------------- src/ui/articleview.cc | 4 ++-- 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/src/fulltextsearch.cc b/src/fulltextsearch.cc index 0695f125..dae3ddd0 100644 --- a/src/fulltextsearch.cc +++ b/src/fulltextsearch.cc @@ -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 ); diff --git a/src/ui/articleview.cc b/src/ui/articleview.cc index 1b58aac4..6375ff44 100644 --- a/src/ui/articleview.cc +++ b/src/ui/articleview.cc @@ -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 );