forked from qt-creator/qt-creator
TextEditor: fix endless loop on adding cursor for selection
Since the find of QTextDocument is line based, it is not possible to find selections spanning multiple lines in the editor. Triggering a find on a search term containing a paragraph separator returnes an invalid QTextCursor which always result in searching from the beginning of the document in the add cursor for selection logic. Prevent that by checking the selected text beforehand and add a safety net in the loop to verify that we do not start over again on an invalid TextCursor. Fixes: QTCREATORBUG-28709 Change-Id: I8c1b9d16e707fefbba6dc0a0a9ef21b8c82ebe19 Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
@@ -7055,12 +7055,13 @@ void TextEditorWidgetPrivate::addSelectionNextFindMatch()
|
||||
return;
|
||||
|
||||
const QTextCursor &firstCursor = cursors.first();
|
||||
QTextDocumentFragment selection = firstCursor.selection();
|
||||
const QString selection = firstCursor.selectedText();
|
||||
if (selection.contains(QChar::ParagraphSeparator))
|
||||
return;
|
||||
QTextDocument *document = firstCursor.document();
|
||||
|
||||
if (Utils::anyOf(cursors, [&firstCursor](const QTextCursor &c) {
|
||||
return c.selection().toPlainText().toCaseFolded()
|
||||
!= firstCursor.selection().toPlainText().toCaseFolded();
|
||||
if (Utils::anyOf(cursors, [selection = selection.toCaseFolded()](const QTextCursor &c) {
|
||||
return c.selectedText().toCaseFolded() != selection;
|
||||
})) {
|
||||
return;
|
||||
}
|
||||
@@ -7069,8 +7070,9 @@ void TextEditorWidgetPrivate::addSelectionNextFindMatch()
|
||||
|
||||
int searchFrom = cursors.last().selectionEnd();
|
||||
while (true) {
|
||||
QTextCursor next = document->find(selection.toPlainText(), searchFrom, findFlags);
|
||||
QTextCursor next = document->find(selection, searchFrom, findFlags);
|
||||
if (next.isNull()) {
|
||||
QTC_ASSERT(searchFrom != 0, return);
|
||||
searchFrom = 0;
|
||||
continue;
|
||||
}
|
||||
|
Reference in New Issue
Block a user