From d44ec5455e24323cff4c244b707f54b815b44187 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Mon, 27 Jan 2025 08:43:38 +0100 Subject: [PATCH] Editor: fix crash when text is auto completed outside of visible area Setting a text cursor also ensures that the cursor is visible. If this operation is done inside a begin/endEditBlock we might operate on an outdated layout which returns a potentially invalid line that causes an assert in the code that ensured the cursor is visible. closing the edit block before setting the text cursor makes sure the layout is invalidated and correctly recalculated before ensuring that the cursor is visible. Fixes: QTCREATORBUG-32401 Change-Id: Ibb6913a8fef9b0d0178f4da0cf9044a25f622007 Reviewed-by: Christian Stenger --- src/plugins/texteditor/texteditor.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp index 8455815504d..8e214bbca81 100644 --- a/src/plugins/texteditor/texteditor.cpp +++ b/src/plugins/texteditor/texteditor.cpp @@ -3225,13 +3225,13 @@ void TextEditorWidget::keyPressEvent(QKeyEvent *e) if (!autoText.isEmpty()) cursor.setPosition(autoText.length() == 1 ? cursor.position() : cursor.anchor()); + if (doEditBlock) + cursor.endEditBlock(); + setTextCursor(cursor); - if (doEditBlock) { - cursor.endEditBlock(); - if (cursorWithinSnippet) - d->m_snippetOverlay->updateEquivalentSelections(textCursor()); - } + if (doEditBlock && cursorWithinSnippet) + d->m_snippetOverlay->updateEquivalentSelections(textCursor()); } if (!ro && e->key() == Qt::Key_Delete && d->m_parenthesesMatchingEnabled)