From 245cb108806d9e27eaedab81260edc09890d378a Mon Sep 17 00:00:00 2001 From: xiaoyifang <105986+xiaoyifang@users.noreply.github.com> Date: Wed, 23 Oct 2024 08:33:44 +0800 Subject: [PATCH] opt: when the marked word is CJK / Han, mark it partially (#1852) * opt: when the marked word is Chinese,mark it partially * [autofix.ci] apply automated fixes * Update src/ui/articleview.cc Co-authored-by: shenleban tongying --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: shenleban tongying --- src/ui/articleview.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/ui/articleview.cc b/src/ui/articleview.cc index 987d2f04..2f9f4e8f 100644 --- a/src/ui/articleview.cc +++ b/src/ui/articleview.cc @@ -2058,11 +2058,19 @@ void ArticleView::highlightFTSResults() return; } + QString accuracy = "exactly"; + + if ( std::any_of( regString.begin(), regString.end(), []( QChar & a ) { + return a.script() == QChar::Script_Han; + } ) ) { + accuracy = "partially"; + } + QString script = QString( "var context = document.querySelector(\"body\");\n" "var instance = new Mark(context);\n instance.unmark();\n" - "instance.mark(\"%1\",{\"accuracy\": \"exactly\"});" ) - .arg( regString ); + "instance.mark(\"%1\",{\"accuracy\": \"%2\"});" ) + .arg( regString, accuracy ); webview->page()->runJavaScript( script ); auto parts = regString.split( " ", Qt::SkipEmptyParts );