diff options
author | David Schulz <david.schulz@qt.io> | 2022-10-07 15:44:06 +0200 |
---|---|---|
committer | David Schulz <david.schulz@qt.io> | 2022-10-13 12:11:58 +0000 |
commit | b2dbc0965c5a5a49c6770674458273f26e453137 (patch) | |
tree | 1272a1db4aaedd4d2ebc8ca5c90ecc88d45f8c3f | |
parent | b4d0db920a11500b3a29f6f0abaaf9a08aa6fa06 (diff) |
Editor: Fix double click in editor behind content
Fixes: QTCREATORBUG-28083
Change-Id: Ie198c2f1c9911ec85ee555ff1058d2528f9e6b7d
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
-rw-r--r-- | src/plugins/texteditor/texteditor.cpp | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp index 2b55229c6c..1cda9db17c 100644 --- a/src/plugins/texteditor/texteditor.cpp +++ b/src/plugins/texteditor/texteditor.cpp @@ -5514,8 +5514,8 @@ void TextEditorWidget::mouseDoubleClickEvent(QMouseEvent *e) } } - QTextCursor oldCursor = multiTextCursor().mainCursor(); - const int oldPosition = oldCursor.position(); + QTextCursor eventCursor = cursorForPosition(QPoint(e->pos().x(), e->pos().y())); + const int eventDocumentPosition = eventCursor.position(); QPlainTextEdit::mouseDoubleClickEvent(e); @@ -5523,19 +5523,19 @@ void TextEditorWidget::mouseDoubleClickEvent(QMouseEvent *e) // event is triggered on a position that is inbetween two whitespaces this event selects the // previous word or nothing if the whitespaces are at the block start. Replace this behavior // with selecting the whitespaces starting from the previous word end to the next word. - const QChar character = characterAt(oldPosition); - const QChar prevCharacter = characterAt(oldPosition - 1); + const QChar character = characterAt(eventDocumentPosition); + const QChar prevCharacter = characterAt(eventDocumentPosition - 1); if (character.isSpace() && prevCharacter.isSpace()) { if (prevCharacter != QChar::ParagraphSeparator) { - oldCursor.movePosition(QTextCursor::PreviousWord); - oldCursor.movePosition(QTextCursor::EndOfWord); + eventCursor.movePosition(QTextCursor::PreviousWord); + eventCursor.movePosition(QTextCursor::EndOfWord); } else if (character == QChar::ParagraphSeparator) { return; // no special handling for empty lines } - oldCursor.movePosition(QTextCursor::NextWord, QTextCursor::KeepAnchor); + eventCursor.movePosition(QTextCursor::NextWord, QTextCursor::KeepAnchor); MultiTextCursor cursor = multiTextCursor(); - cursor.replaceMainCursor(oldCursor); + cursor.replaceMainCursor(eventCursor); setMultiTextCursor(cursor); } } |