Editors: Add an option to enable/disable the camel case navigation.

The user can change the setting in Option->Text Editor->Behavior.

Reviewer's note: We do have alternative ways to disable camel-case
operations through the shortcuts. Nevertheless, this particular option
has been quite requested since it disables every camel-case based
operation at once. In addition, it seems that the shortcuts are still
not "visible" or "expected" for many users.

Change-Id: I04364760f4b43123fd9e06c0c52ba9e6a5688e2c
Merge-request: 392
Reviewed-on: http://codereview.qt-project.org/6419
Reviewed-by: Leandro T. C. Melo <leandro.melo@nokia.com>
Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com>
This commit is contained in:
Nicolas Arnaud-Cormos
2011-09-19 19:00:53 +02:00
committed by Leandro T. C. Melo
parent 14d9328072
commit 7fc4de0b65
6 changed files with 48 additions and 7 deletions

View File

@@ -1498,9 +1498,9 @@ bool BaseTextEditorWidget::cursorMoveKeyEvent(QKeyEvent *e)
bool visualNavigation = cursor.visualNavigation();
cursor.setVisualNavigation(true);
if (op == QTextCursor::WordRight) {
if (camelCaseNavigationEnabled() && op == QTextCursor::WordRight) {
camelCaseRight(cursor, mode);
} else if (op == QTextCursor::WordLeft) {
} else if (camelCaseNavigationEnabled() && op == QTextCursor::WordLeft) {
camelCaseLeft(cursor, mode);
} else {
cursor.movePosition(op, mode);
@@ -1643,7 +1643,10 @@ void BaseTextEditorWidget::keyPressEvent(QKeyEvent *e)
e->accept();
QTextCursor c = textCursor();
int pos = c.position();
camelCaseLeft(c, QTextCursor::MoveAnchor);
if (camelCaseNavigationEnabled())
camelCaseLeft(c, QTextCursor::MoveAnchor);
else
c.movePosition(QTextCursor::StartOfWord, QTextCursor::MoveAnchor);
int targetpos = c.position();
forever {
handleBackspaceKey();
@@ -1656,13 +1659,19 @@ void BaseTextEditorWidget::keyPressEvent(QKeyEvent *e)
} else if (!ro && e == QKeySequence::DeleteStartOfWord && !textCursor().hasSelection()) {
e->accept();
QTextCursor c = textCursor();
camelCaseLeft(c, QTextCursor::KeepAnchor);
if (camelCaseNavigationEnabled())
camelCaseLeft(c, QTextCursor::KeepAnchor);
else
c.movePosition(QTextCursor::StartOfWord, QTextCursor::KeepAnchor);
c.removeSelectedText();
return;
} else if (!ro && e == QKeySequence::DeleteEndOfWord && !textCursor().hasSelection()) {
e->accept();
QTextCursor c = textCursor();
camelCaseRight(c, QTextCursor::KeepAnchor);
if (camelCaseNavigationEnabled())
camelCaseRight(c, QTextCursor::KeepAnchor);
else
c.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
c.removeSelectedText();
return;
} else switch (e->key()) {
@@ -2308,6 +2317,16 @@ bool BaseTextEditorWidget::constrainTooltips() const
return d->m_behaviorSettings.m_constrainTooltips;
}
void BaseTextEditorWidget::setCamelCaseNavigationEnabled(bool b)
{
d->m_behaviorSettings.m_camelCaseNavigation = b;
}
bool BaseTextEditorWidget::camelCaseNavigationEnabled() const
{
return d->m_behaviorSettings.m_camelCaseNavigation;
}
void BaseTextEditorWidget::setRevisionsVisible(bool b)
{
d->m_revisionsVisible = b;