forked from qt-creator/qt-creator
Editor: improve expanding block selection
Replace the main cursor with a block selection instead of a normal selection when using alt+shift+LMB. This is more in line with other IDEs and also feels more natural. Change-Id: Id4dba7cec65ddeb34ab525d90a41aebf78457d0d Reviewed-by: Andrii Semkiv <andrii.semkiv@qt.io> Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
@@ -7173,9 +7173,23 @@ void TextEditorWidget::mousePressEvent(QMouseEvent *e)
|
||||
const QTextCursor &cursor = cursorForPosition(e->pos());
|
||||
if (e->modifiers() & Qt::AltModifier && !(e->modifiers() & Qt::ControlModifier)) {
|
||||
if (e->modifiers() & Qt::ShiftModifier) {
|
||||
QTextCursor c = multiCursor.mainCursor();
|
||||
c.setPosition(cursor.position(), QTextCursor::KeepAnchor);
|
||||
multiCursor.replaceMainCursor(c);
|
||||
const QTextCursor anchor = multiCursor.takeMainCursor();
|
||||
|
||||
const TabSettings tabSettings = d->m_document->tabSettings();
|
||||
int eventColumn
|
||||
= tabSettings.columnAt(cursor.block().text(), cursor.positionInBlock());
|
||||
if (cursor.positionInBlock() == cursor.block().length() - 1) {
|
||||
eventColumn += int(
|
||||
(e->pos().x() - cursorRect(cursor).center().x()) / d->charWidth());
|
||||
}
|
||||
|
||||
const int anchorColumn
|
||||
= tabSettings.columnAt(anchor.block().text(), anchor.positionInBlock());
|
||||
const TextEditorWidgetPrivate::BlockSelection blockSelection
|
||||
= {cursor.blockNumber(), eventColumn, anchor.blockNumber(), anchorColumn};
|
||||
|
||||
multiCursor.addCursors(d->generateCursorsForBlockSelection(blockSelection));
|
||||
setMultiTextCursor(multiCursor);
|
||||
} else {
|
||||
multiCursor.addCursor(cursor);
|
||||
}
|
||||
|
Reference in New Issue
Block a user