opt: when the marked word is CJK / Han, mark it partially (#1852)
Some checks are pending
SonarCloud / Build and analyze (push) Waiting to run

* 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 <shenlebantongying@gmail.com>

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: shenleban tongying <shenlebantongying@gmail.com>
This commit is contained in:
xiaoyifang 2024-10-23 08:33:44 +08:00 committed by GitHub
parent 3e16a0cccf
commit 245cb10880
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2058,11 +2058,19 @@ void ArticleView::highlightFTSResults()
return; 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( QString script = QString(
"var context = document.querySelector(\"body\");\n" "var context = document.querySelector(\"body\");\n"
"var instance = new Mark(context);\n instance.unmark();\n" "var instance = new Mark(context);\n instance.unmark();\n"
"instance.mark(\"%1\",{\"accuracy\": \"exactly\"});" ) "instance.mark(\"%1\",{\"accuracy\": \"%2\"});" )
.arg( regString ); .arg( regString, accuracy );
webview->page()->runJavaScript( script ); webview->page()->runJavaScript( script );
auto parts = regString.split( " ", Qt::SkipEmptyParts ); auto parts = regString.split( " ", Qt::SkipEmptyParts );