fix : fulltext search will crash

close issue #69
This commit is contained in:
Xiao YiFang 2022-05-19 20:28:52 +08:00
parent 0bd724b313
commit 15d9104f2c

View file

@ -2482,6 +2482,15 @@ void ArticleView::highlightFTSResults()
{
closeSearch();
// Clear any current selection
if( ui.definition->selectedText().size() )
{
ui.definition->page()->runJavaScript( "window.getSelection().removeAllRanges();_=0;" );
}
ui.definition->page()->toPlainText(
[ & ]( const QString pageText )
{
const QUrl & url = ui.definition->url();
bool ignoreDiacritics = Utils::Url::hasQueryItem( url, "ignore_diacritics" );
@ -2507,18 +2516,8 @@ void ArticleView::highlightFTSResults()
if( regexp.pattern().isEmpty() || !regexp.isValid() )
return;
sptr< AccentMarkHandler > marksHandler = ignoreDiacritics ? new DiacriticsHandler : new AccentMarkHandler;
// Clear any current selection
if( ui.definition->selectedText().size() )
{
ui.definition->page()->runJavaScript( "window.getSelection().removeAllRanges();_=0;" );
}
ui.definition->page()->toPlainText(
[ & ]( const QString pageText )
{
marksHandler->setText( pageText );
QRegularExpressionMatchIterator it = regexp.globalMatch( marksHandler->normalizedText() );
@ -2547,7 +2546,7 @@ void ArticleView::highlightFTSResults()
ftsSearchMatchCase = Utils::Url::hasQueryItem( url, "matchcase" );
QWebEnginePage::FindFlags flags( 0 );
QWebEnginePage::FindFlags flags( QWebEnginePage::FindBackward );
if( ftsSearchMatchCase )
flags |= QWebEnginePage::FindCaseSensitively;