From b052fa0f05f0c6bdeebf5da59805ff3dd5f87f42 Mon Sep 17 00:00:00 2001 From: Le Tan Date: Thu, 13 Sep 2018 19:59:58 +0800 Subject: [PATCH] Editor: fix find hanging bug --- src/veditor.cpp | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/veditor.cpp b/src/veditor.cpp index cc652f16..203a044e 100644 --- a/src/veditor.cpp +++ b/src/veditor.cpp @@ -863,6 +863,21 @@ void VEditor::highlightIncrementalSearchedWord(const QTextCursor &p_cursor) highlightExtraSelections(true); } +static bool isRegularExpressionSupported(const QRegExp &p_reg) +{ + if (!p_reg.isValid()) { + return false; + } + + // FIXME: hang bug in Qt's find(). + QRegExp test("[$^]+"); + if (test.exactMatch(p_reg.pattern())) { + return false; + } + + return true; +} + // Use QPlainTextEdit::find() instead of QTextDocument::find() because the later has // bugs in searching backward. bool VEditor::findTextHelper(const QString &p_text, @@ -884,14 +899,11 @@ bool VEditor::findTextHelper(const QString &p_text, QRegExp exp; if (useRegExp) { useRegExp = true; - // FIXME: hang bug in Qt's find(). - QRegExp test("[$^]+"); - if (test.exactMatch(p_text)) { - return false; - } - exp = QRegExp(p_text, caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive); + if (!isRegularExpressionSupported(exp)) { + return false; + } } // Store current state of the cursor. @@ -1553,7 +1565,7 @@ QList VEditor::findTextAllInRange(const QTextDocument *p_doc, int p_end) { QList results; - if (!p_reg.isValid()) { + if (!isRegularExpressionSupported(p_reg)) { return results; }