From f0dba78f4837b33dd83450e841b39aaa233da301 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Mon, 2 Jan 2023 12:22:42 +0100 Subject: 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: Reviewed-by: Eike Ziller --- src/plugins/texteditor/snippets/snippetoverlay.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/plugins/texteditor/snippets/snippetoverlay.cpp') 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 ¤tIndex = indexForCursor(cursor); + if (currentIndex == m_finalSelectionIndex) { + accept(); + return; + } if (currentIndex < 0) return; + QTC_ASSERT(currentIndex < m_selections.size(), return); const QString ¤tText = cursorForIndex(currentIndex).selectedText(); const QList &equivalents = m_variables.value(m_selections[currentIndex].variableIndex); for (int i : equivalents) { -- cgit v1.2.1