summaryrefslogtreecommitdiff
path: root/src/plugins/texteditor/snippets/snippetoverlay.cpp
diff options
context:
space:
mode:
authorDavid Schulz <david.schulz@qt.io>2023-01-02 12:22:42 +0100
committerDavid Schulz <david.schulz@qt.io>2023-01-03 09:58:07 +0000
commitf0dba78f4837b33dd83450e841b39aaa233da301 (patch)
tree7af4438231a0bfac7195b89e956d551cc9136af8 /src/plugins/texteditor/snippets/snippetoverlay.cpp
parentbd679b61d119ab516c907e134dfb146fd609fcab (diff)
downloadqt-creator-f0dba78f4837b33dd83450e841b39aaa233da301.tar.gz
Editor: fix crashing on updating snippet selections
The final selection is not tracked in m_selections and needs to be handled explicitly. Also add an assert preventing unconditionally accessing an out of bounds element of m_selections. Fixes: QTCREATORBUG-28631 Change-Id: I1898418b1126bdaffccbdf0e483e2c659d191917 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Diffstat (limited to 'src/plugins/texteditor/snippets/snippetoverlay.cpp')
-rw-r--r--src/plugins/texteditor/snippets/snippetoverlay.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/plugins/texteditor/snippets/snippetoverlay.cpp b/src/plugins/texteditor/snippets/snippetoverlay.cpp
index 6824c0470a..f7b3cf80c9 100644
--- a/src/plugins/texteditor/snippets/snippetoverlay.cpp
+++ b/src/plugins/texteditor/snippets/snippetoverlay.cpp
@@ -38,8 +38,13 @@ void SnippetOverlay::setFinalSelection(const QTextCursor &cursor, const QColor &
void SnippetOverlay::updateEquivalentSelections(const QTextCursor &cursor)
{
const int &currentIndex = indexForCursor(cursor);
+ if (currentIndex == m_finalSelectionIndex) {
+ accept();
+ return;
+ }
if (currentIndex < 0)
return;
+ QTC_ASSERT(currentIndex < m_selections.size(), return);
const QString &currentText = cursorForIndex(currentIndex).selectedText();
const QList<int> &equivalents = m_variables.value(m_selections[currentIndex].variableIndex);
for (int i : equivalents) {