diff --git a/article_netmgr.cc b/article_netmgr.cc index e63ebfff..db2aa0e9 100644 --- a/article_netmgr.cc +++ b/article_netmgr.cc @@ -131,22 +131,11 @@ using std::string; emit errorOccurred( code ); } -// void AllowFrameReply::readDataFromBase() -// { -//// QByteArray data; -//// data.resize( baseReply->bytesAvailable() ); -//// baseReply->read( data.data(), data.size() ); -//// buffer += data; -// emit readyRead(); -// } - qint64 AllowFrameReply::readData( char * data, qint64 maxSize ) { auto bytesAvailable= baseReply->bytesAvailable(); qint64 size = qMin( maxSize, bytesAvailable ); baseReply->read( data, size ); -// memcpy( data, buffer.data(), size ); -// buffer.remove( 0, size ); return size; } diff --git a/articleview.cc b/articleview.cc index 23940893..b70e2077 100644 --- a/articleview.cc +++ b/articleview.cc @@ -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 ) ) { @@ -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; diff --git a/articleview.hh b/articleview.hh index 00d92a64..abe6785c 100644 --- a/articleview.hh +++ b/articleview.hh @@ -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 diff --git a/epwing.cc b/epwing.cc index 9d67cd2d..cd5eec5c 100644 --- a/epwing.cc +++ b/epwing.cc @@ -1054,8 +1054,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( for( ; ; ) { - //skip too long headword - if( !head.headword.isEmpty() && head.headword.size() < 30 ) + if( !head.headword.isEmpty() ) { uint32_t offset = chunks.startNewBlock(); chunks.addToBlock( &head.page, sizeof( head.page ) ); diff --git a/epwing_book.cc b/epwing_book.cc index 111f031a..89aa6959 100644 --- a/epwing_book.cc +++ b/epwing_book.cc @@ -899,7 +899,7 @@ bool EpwingBook::getNextHeadword( EpwingHeadword & head ) } else { - allHeadwordPositions[ head.headword ]< baseFontsMap, customFontsMap; QVector< int > refPages, refOffsets; - QMap< QString, QList > allHeadwordPositions; + QMap< QString, QList< EWPos > > allHeadwordPositions; QVector< EWPos > LinksQueue; int refOpenCount, refCloseCount; static Mutex libMutex; diff --git a/mainwindow.cc b/mainwindow.cc index 28ad0dc8..8f5df588 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -1244,6 +1244,10 @@ void MainWindow::closeEvent( QCloseEvent * ev ) void MainWindow::quitApp() { + if( inspector && inspector->isVisible() ) + { + inspector->hide(); + } commitData(); qApp->quit(); }