diff options
author | David Schulz <david.schulz@qt.io> | 2022-04-22 13:56:22 +0200 |
---|---|---|
committer | David Schulz <david.schulz@qt.io> | 2022-04-29 07:12:23 +0000 |
commit | 58b0a5056c3afe922a2fe8570735da03fb9c3db5 (patch) | |
tree | 5a12fdff5ed233985766226e9ab0a61f383ca56f /src/plugins | |
parent | 703dbd9c798f4a373f8c48c477a4a67fc7ae9408 (diff) |
Editor: Allow selecting a group of whitespaces with double click
Fixes: QTCREATORBUG-24607
Change-Id: I993e2c3a8f1054fc6787cca8e22704fb5b2ab9d1
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/texteditor/texteditor.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp index 318464fb7f..28dca256e6 100644 --- a/src/plugins/texteditor/texteditor.cpp +++ b/src/plugins/texteditor/texteditor.cpp @@ -5493,7 +5493,30 @@ void TextEditorWidget::mouseDoubleClickEvent(QMouseEvent *e) } } + QTextCursor oldCursor = multiTextCursor().mainCursor(); + const int oldPosition = oldCursor.position(); + QPlainTextEdit::mouseDoubleClickEvent(e); + + // QPlainTextEdit::mouseDoubleClickEvent just selects the word under the text cursor. If 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 + // 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); + + if (character.isSpace() && prevCharacter.isSpace()) { + if (prevCharacter != QChar::ParagraphSeparator) { + oldCursor.movePosition(QTextCursor::PreviousWord); + oldCursor.movePosition(QTextCursor::EndOfWord); + } else if (character == QChar::ParagraphSeparator) { + return; // no special handling for empty lines + } + oldCursor.movePosition(QTextCursor::NextWord, QTextCursor::KeepAnchor); + MultiTextCursor cursor = multiTextCursor(); + cursor.replaceMainCursor(oldCursor); + setMultiTextCursor(cursor); + } } void TextEditorWidgetPrivate::setClipboardSelection() |