Skip to content

Commit

Permalink
fix: merge conflict from upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyifang committed May 24, 2022
2 parents bb9811b + f07ba75 commit c6811db
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
23 changes: 20 additions & 3 deletions articleview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2570,11 +2570,9 @@ void ArticleView::highlightFTSResults()
if( ftsSearchMatchCase )
flags |= QWebEnginePage::FindCaseSensitively;

for( int x = 0; x < allMatches.size(); x++ )
ui.definition->findText( allMatches.at( x ), flags );

if( !allMatches.isEmpty() )
{
highlightAllFtsOccurences( flags );
ui.definition->findText( allMatches.at( 0 ), flags );
// if( ui.definition->findText( allMatches.at( 0 ), flags ) )
{
Expand All @@ -2591,6 +2589,25 @@ void ArticleView::highlightFTSResults()
} );
}

void ArticleView::highlightAllFtsOccurences( QWebEnginePage::FindFlags flags )
{
// Usually allMatches contains mostly duplicates. Thus searching for each element of
// allMatches to highlight them takes a long time => collect unique elements into a
// set and search for them instead.
// Don't use QList::toSet() or QSet's range constructor because they reserve space
// for QList::size() elements, whereas the final QSet size is likely 1 or 2.
QSet< QString > uniqueMatches;
for( int x = 0; x < allMatches.size(); ++x )
{
QString const & match = allMatches.at( x );
// Consider words that differ only in case equal if the search is case-insensitive.
uniqueMatches.insert( ftsSearchMatchCase ? match : match.toLower() );
}

for( QSet< QString >::const_iterator it = uniqueMatches.constBegin(); it != uniqueMatches.constEnd(); ++it )
ui.definition->findText( *it, flags );
}

void ArticleView::setActiveDictIds(ActiveDictIds ad) {
// ignore all other signals.
qDebug() << "receive dicts, current word:" << currentWord << ad.word << ":" << ad.dictIds;
Expand Down
2 changes: 1 addition & 1 deletion articleview.hh
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ class ArticleView: public QFrame
int ftsPosition;

void highlightFTSResults();
void highlightAllFtsOccurences( QWebEnginePage::FindFlags flags );
void performFtsFindOperation( bool backwards );
void showFindButtons();

public:
/// The popupView flag influences contents of the context menus to be
Expand Down
3 changes: 3 additions & 0 deletions epwing_book.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,9 @@ void EpwingBook::getArticle( QString & headword, QString & articleText,
headword = QString::fromUtf8( buffer, length );
finalizeText( headword );

if( text_only )
fixHeadword( headword );

articleText = getText( pos.page, pos.offset, text_only );
}

Expand Down

0 comments on commit c6811db

Please sign in to comment.