Index: /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogPage.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogPage.cpp	(revision 78461)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogPage.cpp	(revision 78462)
@@ -342,14 +342,2 @@
         m_pTextEdit->setCurrentFont(font);
 }
-
-void UIVMLogPage::setSearchResultOverlayShowHide(bool fShow)
-{
-    if (m_pTextEdit)
-        m_pTextEdit->setSearchResultOverlayShowHide(fShow);
-}
-
-void UIVMLogPage::setSearchMatchCount(int iMatchCount)
-{
-    if (m_pTextEdit)
-        m_pTextEdit->setSearchMatchCount(iMatchCount);
-}
Index: /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogPage.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogPage.h	(revision 78461)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogPage.h	(revision 78462)
@@ -117,7 +117,4 @@
     void setCurrentFont(QFont font);
 
-    void setSearchResultOverlayShowHide(bool fShow);
-    void setSearchMatchCount(int iMatchCount);
-
 private slots:
 
Index: /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerSearchPanel.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerSearchPanel.cpp	(revision 78461)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerSearchPanel.cpp	(revision 78462)
@@ -82,6 +82,4 @@
     , m_pMatchWholeWordCheckBox(0)
     , m_pHighlightAllCheckBox(0)
-    , m_iSearchCursorPosition(0)
-    , m_iMatchCount(0)
 {
     /* Prepare: */
@@ -91,7 +89,6 @@
 void UIVMLogViewerSearchPanel::refresh()
 {
-    m_iSearchCursorPosition = 0;
     /* We start the search from the end of the doc. assuming log's end is more interesting: */
-    search(BackwardSearch, true);
+    performSearch(BackwardSearch, true);
     emit sigHighlightingUpdated();
 }
@@ -99,7 +96,7 @@
 void UIVMLogViewerSearchPanel::reset()
 {
-    m_iSearchCursorPosition = 0;
+    m_iSelectedMatchIndex = 0;
     m_matchLocationVector.clear();
-    setMatchCount(0);
+    m_matchedCursorPosition.clear();
     if (m_pSearchEditor)
         m_pSearchEditor->reset();
@@ -118,5 +115,5 @@
 int UIVMLogViewerSearchPanel::matchCount() const
 {
-    return m_iMatchCount;
+    return m_matchedCursorPosition.size();
 }
 
@@ -140,14 +137,13 @@
     m_pPreviousButton->setEnabled(!strSearchString.isEmpty());
 
-
     /* If search-string is not empty: */
     if (!strSearchString.isEmpty())
     {
         /* Reset the position to force the search restart from the document's end: */
-        m_iSearchCursorPosition = 0;
-        search(BackwardSearch, true);
+        performSearch(BackwardSearch, true);
         emit sigHighlightingUpdated();
         return;
     }
+
     /* If search-string is empty, reset cursor position: */
     if (!viewer())
@@ -165,8 +161,8 @@
         pBrowser->setTextCursor(cursor);
     }
-    m_iSearchCursorPosition = -1;
-    setMatchCount(0);
+    m_matchedCursorPosition.clear();
+    m_matchLocationVector.clear();
+    clearHighlighting();
     emit sigSearchUpdated();
-    clearHighlighting();
 }
 
@@ -201,4 +197,9 @@
 {
     refresh();
+}
+
+void UIVMLogViewerSearchPanel::sltSelectNextPreviousMatch()
+{
+    moveSelection(sender() == m_pNextButton);
 }
 
@@ -282,6 +283,6 @@
 {
     connect(m_pSearchEditor, &UIVMLogViewerSearchField::textChanged, this, &UIVMLogViewerSearchPanel::sltSearchTextChanged);
-    connect(m_pNextButton, &QIToolButton::clicked, this, &UIVMLogViewerSearchPanel::findNext);
-    connect(m_pPreviousButton, &QIToolButton::clicked, this, &UIVMLogViewerSearchPanel::findPrevious);
+    connect(m_pNextButton, &QIToolButton::clicked, this, &UIVMLogViewerSearchPanel::sltSelectNextPreviousMatch);
+    connect(m_pPreviousButton, &QIToolButton::clicked, this, &UIVMLogViewerSearchPanel::sltSelectNextPreviousMatch);
 
     connect(m_pHighlightAllCheckBox, &QCheckBox::stateChanged,
@@ -413,9 +414,9 @@
         /* Select all the text: */
         m_pSearchEditor->selectAll();
-        m_pSearchEditor->setMatchCount(m_iMatchCount);
-    }
-}
-
-void UIVMLogViewerSearchPanel::search(SearchDirection direction, bool highlight)
+        m_pSearchEditor->setMatchCount(m_matchedCursorPosition.size());
+    }
+}
+
+void UIVMLogViewerSearchPanel::performSearch(SearchDirection , bool )
 {
     QPlainTextEdit *pTextEdit = textEdit();
@@ -429,5 +430,4 @@
 
     const QString &searchString = m_pSearchEditor->text();
-    setMatchCount(countMatches(pDocument, searchString));
     emit sigSearchUpdated();
 
@@ -435,59 +435,14 @@
         return;
 
-    QTextCursor endCursor(pDocument);
-    endCursor.movePosition(QTextCursor::End);
-    QTextCursor startCursor(pDocument);
-
+    findAll(pDocument, searchString);
+    m_iSelectedMatchIndex = 0;
+    selectMatch(m_iSelectedMatchIndex, searchString);
+    if (m_pSearchEditor)
+    {
+        m_pSearchEditor->setMatchCount(m_matchedCursorPosition.size());
+        m_pSearchEditor->setScroolToIndex(m_matchedCursorPosition.empty() ? -1 : 0);
+    }
     if (m_pHighlightAllCheckBox->isChecked())
-    {
-        if (highlight)
-            highlightAll(pDocument, searchString);
-    }
-    else
-        m_matchLocationVector.clear();
-
-    QTextCursor resultCursor(pDocument);
-    int startPosition = m_iSearchCursorPosition;
-    if (direction == BackwardSearch)
-        startPosition -= searchString.length();
-    resultCursor = pDocument->find(searchString, startPosition, constructFindFlags(direction));
-
-    /* Decide whether to wrap around or to end the search */
-    if (resultCursor.isNull())
-    {
-        /* End the search if we search the whole document with no find: */
-        if ((direction == ForwardSearch && startPosition == startCursor.position()) ||
-            (direction == BackwardSearch && startPosition == endCursor.position()))
-        {
-            return;
-        }
-        /* Wrap the search */
-        if (direction == ForwardSearch)
-        {
-            m_iSearchCursorPosition = startCursor.position();
-            search(ForwardSearch, false);
-            return;
-        }
-        else
-        {
-            /* Set the search position away from the end position to be
-               able to find the string at the end of the document: */
-            m_iSearchCursorPosition = endCursor.position() + searchString.length();
-            search(BackwardSearch, false);
-            return;
-        }
-    }
-    pTextEdit->setTextCursor(resultCursor);
-    m_iSearchCursorPosition = resultCursor.position();
-}
-
-void UIVMLogViewerSearchPanel::findNext()
-{
-    search(ForwardSearch, false);
-}
-
-void UIVMLogViewerSearchPanel::findPrevious()
-{
-    search(BackwardSearch, false);
+        highlightAll(pDocument, searchString);
 }
 
@@ -496,9 +451,7 @@
     if (!viewer())
         return;
-    m_matchLocationVector.clear();
     QTextDocument* pDocument = textDocument();
     if (pDocument)
         pDocument->undo();
-
     emit sigHighlightingUpdated();
 }
@@ -518,20 +471,70 @@
     cursor.beginEditBlock();
     colorFormat.setBackground(Qt::yellow);
-    int lineCount = pDocument->lineCount();
-    QTextDocument::FindFlags flags = constructFindFlags(ForwardSearch);
-    while (!highlightCursor.isNull() && !highlightCursor.atEnd())
-    {
-        /* Hightlighting searches is always from the top of the document forward: */
-        highlightCursor = pDocument->find(searchString, highlightCursor, flags);
+    for (int i = 0; i < m_matchedCursorPosition.size(); ++i)
+    {
+        highlightCursor.setPosition(m_matchedCursorPosition[i]);
+        highlightCursor.setPosition(m_matchedCursorPosition[i] + searchString.length(), QTextCursor::KeepAnchor);
+
         if (!highlightCursor.isNull())
         {
             highlightCursor.mergeCharFormat(colorFormat);
+        }
+    }
+    cursor.endEditBlock();
+}
+
+void UIVMLogViewerSearchPanel::findAll(QTextDocument *pDocument, const QString &searchString)
+{
+    if (!pDocument)
+        return;
+    m_matchedCursorPosition.clear();
+    m_matchLocationVector.clear();
+    if (searchString.isEmpty())
+        return;
+    QTextCursor cursor(pDocument);
+    QTextDocument::FindFlags flags = constructFindFlags(ForwardSearch);
+    int lineCount = pDocument->lineCount();
+    while (!cursor.isNull() && !cursor.atEnd())
+    {
+        cursor = pDocument->find(searchString, cursor, flags);
+
+        if (!cursor.isNull())
+        {
+            m_matchedCursorPosition << cursor.position() - searchString.length();
             /* The following assumes we have single line blocks only: */
-            int cursorLine = pDocument->findBlock(highlightCursor.position()).blockNumber();
+            int cursorLine = pDocument->findBlock(cursor.position()).blockNumber();
             if (lineCount != 0)
                 m_matchLocationVector.push_back(cursorLine / static_cast<float>(lineCount));
         }
     }
-    cursor.endEditBlock();
+}
+
+void UIVMLogViewerSearchPanel::selectMatch(int iMatchIndex, const QString &searchString)
+{
+    if (!textEdit())
+        return;
+    if (searchString.isEmpty())
+        return;
+    if (iMatchIndex < 0 || iMatchIndex >= m_matchedCursorPosition.size())
+        return;
+
+    QTextCursor cursor = textEdit()->textCursor();
+    /* Move the cursor to the beginning of the matched string: */
+    cursor.setPosition(m_matchedCursorPosition.at(iMatchIndex), QTextCursor::MoveAnchor);
+    /* Move the cursor to the end of the matched string while keeping the anchor at the begining thus selecting the text: */
+    cursor.setPosition(m_matchedCursorPosition.at(iMatchIndex)+searchString.length(), QTextCursor::KeepAnchor);
+    textEdit()->setTextCursor(cursor);
+    return;
+}
+
+void UIVMLogViewerSearchPanel::moveSelection(bool fForward)
+{
+    if (fForward)
+        m_iSelectedMatchIndex = m_iSelectedMatchIndex >= m_matchedCursorPosition.size() - 1 ? 0 : (m_iSelectedMatchIndex + 1);
+    else
+        m_iSelectedMatchIndex = m_iSelectedMatchIndex <= 0 ? m_matchedCursorPosition.size() - 1 : (m_iSelectedMatchIndex - 1);
+    selectMatch(m_iSelectedMatchIndex, m_pSearchEditor->text());
+    if (m_pSearchEditor)
+        m_pSearchEditor->setScroolToIndex(m_iSelectedMatchIndex);
 }
 
@@ -555,13 +558,4 @@
 }
 
-void UIVMLogViewerSearchPanel::setMatchCount(int iCount)
-{
-    if (m_iMatchCount == iCount)
-        return;
-    m_iMatchCount = iCount;
-    if (m_pSearchEditor)
-        m_pSearchEditor->setMatchCount(iCount);
-}
-
 QTextDocument::FindFlags UIVMLogViewerSearchPanel::constructFindFlags(SearchDirection eDirection) const
 {
Index: /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerSearchPanel.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerSearchPanel.h	(revision 78461)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerSearchPanel.h	(revision 78462)
@@ -82,8 +82,5 @@
     void sltCaseSentitiveCheckBox();
     void sltMatchWholeWordCheckBox();
-    /** Forward search routine wrapper. */
-    void findNext();
-    /** Backward search routine wrapper. */
-    void findPrevious();
+    void sltSelectNextPreviousMatch();
 
 private:
@@ -98,11 +95,14 @@
       * @param  highlight      if false highlight function is not called
                                thus we avoid calling highlighting for the same string repeatedly. */
-    void search(SearchDirection eDirection, bool highlight);
+    void performSearch(SearchDirection eDirection, bool highlight);
     void highlightAll(QTextDocument *pDocument, const QString &searchString);
+    void findAll(QTextDocument *pDocument, const QString &searchString);
+    void selectMatch(int iMatchIndex, const QString &searchString);
+    void moveSelection(bool fForward);
+
     /** Constructs the find flags for QTextDocument::find function. */
     QTextDocument::FindFlags constructFindFlags(SearchDirection eDirection) const;
     /** Searches the whole document and return the number of matches to the current search term. */
     int countMatches(QTextDocument *pDocument, const QString &searchString) const;
-    void setMatchCount(int iCount);
     /** Holds the instance of search-editor we create. */
     UISearchLineEdit *m_pSearchEditor;
@@ -114,13 +114,11 @@
     QCheckBox    *m_pMatchWholeWordCheckBox;
     QCheckBox    *m_pHighlightAllCheckBox;
-
-    /** Holds the position where we start the next search. */
-    int          m_iSearchCursorPosition;
-    /** Holds the number of the matches for the string. 0 for no matches. */
-    int          m_iMatchCount;
-
-    /** Stores relative positions of the lines of the matches. The values are [0,1]
+    /** Stores relative positions of the lines of the matches wrt. total # of lines. The values are in [0,1]
         0 being the first line 1 being the last. */
     QVector<float> m_matchLocationVector;
+    /** Document positions of the cursors within th document for all matches. */
+    QVector<int>   m_matchedCursorPosition;
+    /** The index of the curently selected item within m_matchedCursorPosition. */
+    int            m_iSelectedMatchIndex;
 };
 
Index: /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerTextEdit.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerTextEdit.cpp	(revision 78461)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerTextEdit.cpp	(revision 78462)
@@ -193,6 +193,4 @@
     , m_bWrapLines(true)
     , m_bHasContextMenu(false)
-    , m_fShowSearchResultOverlay(0)
-    , m_iMatchCount(0)
 {
     configure();
@@ -241,22 +239,4 @@
     if (m_pLineNumberArea)
         m_pLineNumberArea->setFont(font);
-}
-
-void UIVMLogViewerTextEdit::setSearchResultOverlayShowHide(bool fShow)
-{
-    if (m_fShowSearchResultOverlay == fShow)
-        return;
-    m_fShowSearchResultOverlay = fShow;
-    if (viewport())
-        viewport()->repaint();
-}
-
-void UIVMLogViewerTextEdit::setSearchMatchCount(int iMatchCount)
-{
-    if (m_iMatchCount == iMatchCount)
-        return;
-    m_iMatchCount = iMatchCount;
-    if (m_fShowSearchResultOverlay && viewport())
-        viewport()->repaint();
 }
 
@@ -386,50 +366,4 @@
 }
 
-void UIVMLogViewerTextEdit::paintEvent(QPaintEvent *pEvent)
-{
-    QIWithRetranslateUI<QPlainTextEdit>::paintEvent(pEvent);
-
-    /* Draw an overlay with text in it to show the number of search matches: */
-    if (viewport() && (m_fShowSearchResultOverlay || m_bShownTextIsFiltered))
-    {
-        QPainter painter(viewport());
-        QColor rectColor = viewport()->palette().color(QPalette::Active, QPalette::Dark);
-        double fontScale = 1.5;
-        rectColor.setAlpha(200);
-
-        QString strText;
-        if (m_fShowSearchResultOverlay)
-            strText = QString("%1 %2").arg(QString::number(m_iMatchCount)).arg(UIVMLogViewerWidget::tr("Matches Found"));
-        if (m_bShownTextIsFiltered)
-        {
-            if (!strText.isEmpty())
-                strText.append(" / ");
-            strText.append(UIVMLogViewerWidget::tr("Filtered"));
-        }
-        /* Space between the text and rectangle border: */
-        QSize textMargin(5, 5);
-        /* Space between the rectangle and viewport edges: */
-        QSize rectMargin(2, 2);
-
-        QSize rectSize(fontScale * QApplication::fontMetrics().width(strText) + textMargin.width(),
-                       fontScale * QApplication::fontMetrics().height() + textMargin.height());
-        QPoint topLeft(viewport()->rect().width() - rectSize.width() - rectMargin.width(),
-                       viewport()->rect().height() - rectSize.height() - rectMargin.height());
-        painter.fillRect(topLeft.x(),topLeft.y(), rectSize.width(), rectSize.height(), rectColor);
-
-
-        QFont pfont = QApplication::font();
-        QColor fontColor(QPalette::WindowText);
-        painter.setPen(fontColor);
-        if (pfont.pixelSize() != -1)
-            pfont.setPixelSize(fontScale * pfont.pixelSize());
-        else
-            pfont.setPointSize(fontScale * pfont.pointSize());
-        painter.setFont(pfont);
-
-        painter.drawText(QRect(topLeft, rectSize), Qt::AlignCenter | Qt::AlignVCenter, strText);
-    }
-}
-
 void UIVMLogViewerTextEdit::sltUpdateLineNumberAreaWidth(int /* newBlockCount */)
 {
Index: /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerTextEdit.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerTextEdit.h	(revision 78461)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerTextEdit.h	(revision 78462)
@@ -69,7 +69,4 @@
     void setCurrentFont(QFont font);
 
-    void setSearchResultOverlayShowHide(bool fShow);
-    void setSearchMatchCount(int iMatchCount);
-
 protected:
 
@@ -78,5 +75,4 @@
     virtual void mouseMoveEvent(QMouseEvent *pEvent) /* override */;
     virtual void leaveEvent(QEvent * pEvent) /* override */;
-    virtual void paintEvent(QPaintEvent *pEvent) /* override */;
     virtual void retranslateUi() /* override */;
 
@@ -117,7 +113,5 @@
     friend class UILineNumberArea;
     bool         m_bHasContextMenu;
-    bool         m_fShowSearchResultOverlay;
-    int          m_iMatchCount;
-};
+ };
 
 
Index: /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.cpp	(revision 78461)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.cpp	(revision 78462)
@@ -310,7 +310,4 @@
     if (!m_pSearchPanel || !currentLogPage())
         return;
-    for (int i = 0; i < m_logPageList.size(); ++i)
-        if (UIVMLogPage *pPage = qobject_cast<UIVMLogPage*>(m_logPageList[i]))
-            pPage->setSearchMatchCount(m_pSearchPanel->matchCount());
 }
 
@@ -767,6 +764,4 @@
             pLogPage->markForError();
         }
-        pLogPage->setSearchResultOverlayShowHide(m_pSearchPanel->isVisible());
-        pLogPage->setSearchMatchCount(m_pSearchPanel->matchCount());
         pLogPage->setScrollBarMarkingsVector(m_pSearchPanel->matchLocationVector());
     }
@@ -872,11 +867,4 @@
     m_visiblePanelsList.removeOne(panel);
     manageEscapeShortCut();
-    /* Hide the search result overlay on the text edit: */
-    if (panel == m_pSearchPanel)
-    {
-        for (int i = 0; i < m_logPageList.size(); ++i)
-            if (UIVMLogPage *pPage = qobject_cast<UIVMLogPage*>(m_logPageList[i]))
-                pPage->setSearchResultOverlayShowHide(false);
-    }
 }
 
@@ -893,12 +881,4 @@
     m_visiblePanelsList.push_back(panel);
     manageEscapeShortCut();
-
-    /* Show the search result overlay on the text edit: */
-    if (panel == m_pSearchPanel)
-    {
-        for (int i = 0; i < m_logPageList.size(); ++i)
-            if (UIVMLogPage *pPage = qobject_cast<UIVMLogPage*>(m_logPageList[i]))
-                pPage->setSearchResultOverlayShowHide(true);
-    }
 }
 
