diff options
author | David Schulz <david.schulz@qt.io> | 2023-01-23 08:21:24 +0100 |
---|---|---|
committer | David Schulz <david.schulz@qt.io> | 2023-01-23 09:58:25 +0000 |
commit | f15cae2bacba3616936a12b0e8f7bea0e660fce0 (patch) | |
tree | 19ce274b6064df89872209631a88f87a039adc4d | |
parent | 0c9d5903eff1f9c1dd20e076602e2826ec10031b (diff) | |
download | qt-creator-f15cae2bacba3616936a12b0e8f7bea0e660fce0.tar.gz |
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>
-rw-r--r-- | src/plugins/texteditor/texteditor.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp index d6bce9d5a0..3b8f5505d6 100644 --- a/src/plugins/texteditor/texteditor.cpp +++ b/src/plugins/texteditor/texteditor.cpp @@ -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; } |