Editor: Fix double click in editor behind content

Fixes: QTCREATORBUG-28083
Change-Id: Ie198c2f1c9911ec85ee555ff1058d2528f9e6b7d
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2022-10-07 15:44:06 +02:00
parent b4d0db920a
commit b2dbc0965c

View File

@@ -5514,8 +5514,8 @@ void TextEditorWidget::mouseDoubleClickEvent(QMouseEvent *e)
} }
} }
QTextCursor oldCursor = multiTextCursor().mainCursor(); QTextCursor eventCursor = cursorForPosition(QPoint(e->pos().x(), e->pos().y()));
const int oldPosition = oldCursor.position(); const int eventDocumentPosition = eventCursor.position();
QPlainTextEdit::mouseDoubleClickEvent(e); 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 // 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 // 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. // with selecting the whitespaces starting from the previous word end to the next word.
const QChar character = characterAt(oldPosition); const QChar character = characterAt(eventDocumentPosition);
const QChar prevCharacter = characterAt(oldPosition - 1); const QChar prevCharacter = characterAt(eventDocumentPosition - 1);
if (character.isSpace() && prevCharacter.isSpace()) { if (character.isSpace() && prevCharacter.isSpace()) {
if (prevCharacter != QChar::ParagraphSeparator) { if (prevCharacter != QChar::ParagraphSeparator) {
oldCursor.movePosition(QTextCursor::PreviousWord); eventCursor.movePosition(QTextCursor::PreviousWord);
oldCursor.movePosition(QTextCursor::EndOfWord); eventCursor.movePosition(QTextCursor::EndOfWord);
} else if (character == QChar::ParagraphSeparator) { } else if (character == QChar::ParagraphSeparator) {
return; // no special handling for empty lines return; // no special handling for empty lines
} }
oldCursor.movePosition(QTextCursor::NextWord, QTextCursor::KeepAnchor); eventCursor.movePosition(QTextCursor::NextWord, QTextCursor::KeepAnchor);
MultiTextCursor cursor = multiTextCursor(); MultiTextCursor cursor = multiTextCursor();
cursor.replaceMainCursor(oldCursor); cursor.replaceMainCursor(eventCursor);
setMultiTextCursor(cursor); setMultiTextCursor(cursor);
} }
} }