C++: Implement context-aware expand / shrink selection actions.

Implement selection expanding / shrinking, that is aware of C++
semantics, thus giving smart selection changing.

Change-Id: I1386a20597fa6bb85c3aa0d8ddfb87cdb3fd7c38
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
Alexandru Croitor
2015-12-20 19:59:00 +01:00
committed by Nikolai Kosjar
parent 8bfdc82c5a
commit bed88818ce
21 changed files with 2650 additions and 14 deletions

View File

@@ -1300,14 +1300,6 @@ void TextEditorWidget::gotoNextWordCamelCaseWithSelection()
setTextCursor(c);
}
static QTextCursor flippedCursor(const QTextCursor &cursor)
{
QTextCursor flipped = cursor;
flipped.clearSelection();
flipped.setPosition(cursor.anchor(), QTextCursor::KeepAnchor);
return flipped;
}
bool TextEditorWidget::selectBlockUp()
{
QTextCursor cursor = textCursor();
@@ -1321,7 +1313,7 @@ bool TextEditorWidget::selectBlockUp()
if (!TextBlockUserData::findNextClosingParenthesis(&cursor, true))
return false;
setTextCursor(flippedCursor(cursor));
setTextCursor(Convenience::flippedCursor(cursor));
d->_q_matchParentheses();
return true;
}
@@ -1346,7 +1338,7 @@ bool TextEditorWidget::selectBlockDown()
if ( cursor != d->m_selectBlockAnchor)
TextBlockUserData::findNextClosingParenthesis(&cursor, true);
setTextCursor(flippedCursor(cursor));
setTextCursor(Convenience::flippedCursor(cursor));
d->_q_matchParentheses();
return true;
}
@@ -5346,6 +5338,11 @@ const MarginSettings &TextEditorWidget::marginSettings() const
return d->m_marginSettings;
}
const BehaviorSettings &TextEditorWidget::behaviorSettings() const
{
return d->m_behaviorSettings;
}
void TextEditorWidgetPrivate::handleHomeKey(bool anchor)
{
QTextCursor cursor = q->textCursor();