From 5da4c61f6c7007ca9d6e56a779fbb24ea82b1f54 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Mon, 2 Nov 2020 11:03:29 +0100 Subject: [PATCH] Debugger: Fix tooltip expression collector Only use the selected text from the text cursor if the requested position is inside the selection. Task-number: QTCREATORBUG-24180 Change-Id: I1d9b07fec2f89c125fa6568aa76130f252e146a4 Reviewed-by: hjk --- src/plugins/debugger/sourceutils.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/plugins/debugger/sourceutils.cpp b/src/plugins/debugger/sourceutils.cpp index a492bb8308f..a76317258c6 100644 --- a/src/plugins/debugger/sourceutils.cpp +++ b/src/plugins/debugger/sourceutils.cpp @@ -259,8 +259,10 @@ QString cppExpressionAt(TextEditorWidget *editorWidget, int pos, const Snapshot snapshot = CppModelManager::instance()->snapshot(); const Document::Ptr document = snapshot.document(fileName); QTextCursor tc = editorWidget->textCursor(); - QString expr = tc.selectedText(); - if (expr.isEmpty()) { + QString expr; + if (tc.hasSelection() && pos >= tc.selectionStart() && pos <= tc.selectionEnd()) { + expr = tc.selectedText(); + } else { tc.setPosition(pos); const QChar ch = editorWidget->characterAt(pos); if (ch.isLetterOrNumber() || ch == '_')