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>
This commit is contained in:
David Schulz
2022-04-22 13:56:22 +02:00
parent 703dbd9c79
commit 58b0a5056c

View File

@@ -5493,7 +5493,30 @@ void TextEditorWidget::mouseDoubleClickEvent(QMouseEvent *e)
} }
} }
QTextCursor oldCursor = multiTextCursor().mainCursor();
const int oldPosition = oldCursor.position();
QPlainTextEdit::mouseDoubleClickEvent(e); 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() void TextEditorWidgetPrivate::setClipboardSelection()