From a3640ac2606b66012faf7f32c7d26a8d7f508bef Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Sat, 29 Nov 2014 00:28:10 +0100 Subject: [PATCH] QTextDocument QRegularExpression search cleanup Code cleanup and improvement Change-Id: I04109e6eaa24e90e24ba89957adca32281d077dc Reviewed-by: Konstantin Ritt --- src/gui/text/qtextdocument.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index 2eb6f232fb..a3dc1f39c4 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -1516,13 +1516,11 @@ static bool findInBlock(const QTextBlock &block, const QRegularExpression &expre } } //we have a hit, return the cursor for that. - break; + *cursor = QTextCursor(block.docHandle(), block.position() + idx); + cursor->setPosition(cursor->position() + match.capturedLength(), QTextCursor::KeepAnchor); + return true; } - if (idx == -1) - return false; - *cursor = qMove(QTextCursor(block.docHandle(), block.position() + idx)); - cursor->setPosition(cursor->position() + match.capturedLength(), QTextCursor::KeepAnchor); - return true; + return false; } /*! @@ -1557,17 +1555,16 @@ QTextCursor QTextDocument::find(const QRegularExpression &expr, int from, FindFl QTextCursor cursor; QTextBlock block = d->blocksFind(pos); + int blockOffset = pos - block.position(); if (!(options & FindBackward)) { - int blockOffset = qMax(0, pos - block.position()); while (block.isValid()) { if (findInBlock(block, expr, blockOffset, options, &cursor)) return cursor; - blockOffset = 0; block = block.next(); + blockOffset = 0; } } else { - int blockOffset = pos - block.position(); while (block.isValid()) { if (findInBlock(block, expr, blockOffset, options, &cursor)) return cursor;