diff --git a/src/abstractlogview.cpp b/src/abstractlogview.cpp index d56155f0d..22ad4d3c7 100644 --- a/src/abstractlogview.cpp +++ b/src/abstractlogview.cpp @@ -1167,21 +1167,25 @@ int AbstractLogView::convertCoordToLine(int yPos) const QPoint AbstractLogView::convertCoordToFilePos( const QPoint& pos ) const { int line = convertCoordToLine( pos.y() ); - if ( line >= logData->getNbLine() ) - line = logData->getNbLine() - 1; + int nbLine = logData->getNbLine(); + if ( line >= nbLine ) + line = nbLine - 1; if ( line < 0 ) line = 0; - // Determine column in screen space and convert it to file space - int column = firstCol + ( pos.x() - leftMarginPx_ ) / charWidth_; + int column = 0; - QString this_line = logData->getExpandedLineString( line ); - const int length = this_line.length(); + if ( nbLine ) { + // Determine column in screen space and convert it to file space + column = firstCol + ( pos.x() - leftMarginPx_ ) / charWidth_; + QString this_line = logData->getExpandedLineString( line ); + const int length = this_line.length(); - if ( column >= length ) - column = length - 1; - if ( column < 0 ) - column = 0; + if ( column >= length ) + column = length - 1; + if ( column < 0 ) + column = 0; + } LOG(logDEBUG4) << "AbstractLogView::convertCoordToFilePos col=" << column << " line=" << line; diff --git a/src/crawlerwidget.cpp b/src/crawlerwidget.cpp index 657d1cd1f..28c1d3559 100644 --- a/src/crawlerwidget.cpp +++ b/src/crawlerwidget.cpp @@ -572,8 +572,10 @@ void CrawlerWidget::changeFilteredViewVisibility( int index ) filteredView->setVisibility( visibility ); - const int lineIndex = logFilteredData_->getLineIndexNumber( currentLineNumber_ ); - filteredView->selectAndDisplayLine( lineIndex ); + if ( logFilteredData_->getNbLine() > 0 ) { + const int lineIndex = logFilteredData_->getLineIndexNumber( currentLineNumber_ ); + filteredView->selectAndDisplayLine( lineIndex ); + } } void CrawlerWidget::addToSearch( const QString& string ) diff --git a/src/utils.h b/src/utils.h index 5e1abd2d7..bb923664e 100644 --- a/src/utils.h +++ b/src/utils.h @@ -118,9 +118,6 @@ LineNumber lookupLineNumber( Iterator begin, Iterator end, LineNumber lineNum ) if ( lowerBound != end ) { lineIndex = std::distance(begin, lowerBound); } - else if (begin != end) { - lineIndex = begin->lineNumber(); - } return lineIndex; }