forked from qt-creator/qt-creator
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:
@@ -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()
|
||||
|
Reference in New Issue
Block a user