forked from qt-creator/qt-creator
Double-click to select current block
This is a Eclipse-like feature, for select enclosing element.
e.g.
int test() {| // Here is the cursor position
...
}
When Double-click, we can select the block: {...}
I think this is a useful feature.
Change-Id: I4ca7ed04056176195d1622714effda9079ae0e44
Reviewed-by: Leandro Melo <leandro.melo@nokia.com>
This commit is contained in:
committed by
Leandro Melo
parent
05d8aeae8d
commit
18b675d32f
@@ -865,7 +865,7 @@ static QTextCursor flippedCursor(const QTextCursor &cursor)
|
||||
return flipped;
|
||||
}
|
||||
|
||||
void BaseTextEditorWidget::selectBlockUp()
|
||||
bool BaseTextEditorWidget::selectBlockUp()
|
||||
{
|
||||
QTextCursor cursor = textCursor();
|
||||
if (!cursor.hasSelection())
|
||||
@@ -873,22 +873,23 @@ void BaseTextEditorWidget::selectBlockUp()
|
||||
else
|
||||
cursor.setPosition(cursor.selectionStart());
|
||||
|
||||
|
||||
if (!TextBlockUserData::findPreviousOpenParenthesis(&cursor, false))
|
||||
return;
|
||||
return false;
|
||||
if (!TextBlockUserData::findNextClosingParenthesis(&cursor, true))
|
||||
return;
|
||||
return false;
|
||||
|
||||
setTextCursor(flippedCursor(cursor));
|
||||
_q_matchParentheses();
|
||||
return true;
|
||||
}
|
||||
|
||||
void BaseTextEditorWidget::selectBlockDown()
|
||||
bool BaseTextEditorWidget::selectBlockDown()
|
||||
{
|
||||
QTextCursor tc = textCursor();
|
||||
QTextCursor cursor = d->m_selectBlockAnchor;
|
||||
|
||||
if (!tc.hasSelection() || cursor.isNull())
|
||||
return;
|
||||
return false;
|
||||
tc.setPosition(tc.selectionStart());
|
||||
|
||||
forever {
|
||||
@@ -904,6 +905,7 @@ void BaseTextEditorWidget::selectBlockDown()
|
||||
|
||||
setTextCursor(flippedCursor(cursor));
|
||||
_q_matchParentheses();
|
||||
return true;
|
||||
}
|
||||
|
||||
void BaseTextEditorWidget::copyLineUp()
|
||||
@@ -4214,6 +4216,18 @@ void BaseTextEditorWidget::mouseReleaseEvent(QMouseEvent *e)
|
||||
QPlainTextEdit::mouseReleaseEvent(e);
|
||||
}
|
||||
|
||||
void BaseTextEditorWidget::mouseDoubleClickEvent(QMouseEvent *e)
|
||||
{
|
||||
QTextCursor cursor = textCursor();
|
||||
const int position = cursor.position();
|
||||
if (TextBlockUserData::findPreviousOpenParenthesis(&cursor, false, true)) {
|
||||
if (position - cursor.position() == 1 && selectBlockUp())
|
||||
return;
|
||||
}
|
||||
|
||||
QPlainTextEdit::mouseDoubleClickEvent(e);
|
||||
}
|
||||
|
||||
void BaseTextEditorWidget::leaveEvent(QEvent *e)
|
||||
{
|
||||
// Clear link emulation when the mouse leaves the editor
|
||||
|
||||
Reference in New Issue
Block a user