Editor: fix find hanging bug

This commit is contained in:
Le Tan 2018-09-13 19:59:58 +08:00
parent 74032f4a08
commit b052fa0f05

View File

@ -863,6 +863,21 @@ void VEditor::highlightIncrementalSearchedWord(const QTextCursor &p_cursor)
highlightExtraSelections(true); 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 // Use QPlainTextEdit::find() instead of QTextDocument::find() because the later has
// bugs in searching backward. // bugs in searching backward.
bool VEditor::findTextHelper(const QString &p_text, bool VEditor::findTextHelper(const QString &p_text,
@ -884,14 +899,11 @@ bool VEditor::findTextHelper(const QString &p_text,
QRegExp exp; QRegExp exp;
if (useRegExp) { if (useRegExp) {
useRegExp = true; useRegExp = true;
// FIXME: hang bug in Qt's find().
QRegExp test("[$^]+");
if (test.exactMatch(p_text)) {
return false;
}
exp = QRegExp(p_text, exp = QRegExp(p_text,
caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive); caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive);
if (!isRegularExpressionSupported(exp)) {
return false;
}
} }
// Store current state of the cursor. // Store current state of the cursor.
@ -1553,7 +1565,7 @@ QList<QTextCursor> VEditor::findTextAllInRange(const QTextDocument *p_doc,
int p_end) int p_end)
{ {
QList<QTextCursor> results; QList<QTextCursor> results;
if (!p_reg.isValid()) { if (!isRegularExpressionSupported(p_reg)) {
return results; return results;
} }