summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPasi Matilainen <pasi.matilainen@digia.com>2012-01-16 07:10:18 (GMT)
committerQt by Nokia <qt-info@nokia.com>2012-02-03 10:10:44 (GMT)
commit1b031759ddfdab9703dfecac13f1ed318da3dafe (patch)
tree05c3e701922ef5aef268a26521fc805a03978ff3 /src
parent882a868486949784206d2ef386ad4e2c0da2b07e (diff)
downloadQt-1b031759ddfdab9703dfecac13f1ed318da3dafe.zip
Qt-1b031759ddfdab9703dfecac13f1ed318da3dafe.tar.gz
Qt-1b031759ddfdab9703dfecac13f1ed318da3dafe.tar.bz2
QTextEdit cursor position fix when moving left/right with selection
When text has been selected in a QTextEdit and the left or right arrow key is pressed, the cursor moves one character beyond the start or end of the selection, when it shouldn't move past the selection. Fixed by moving the cursor to the right place when a selection is active. Task-number: QTBUG-22853 Change-Id: I9ea1863436db98627a6fd041ce554cf10be26493 Reviewed-by: Jiang Jiang <jiang.jiang@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/gui/text/qtextcursor.cpp26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/gui/text/qtextcursor.cpp b/src/gui/text/qtextcursor.cpp
index 51db578..e6af105 100644
--- a/src/gui/text/qtextcursor.cpp
+++ b/src/gui/text/qtextcursor.cpp
@@ -421,11 +421,18 @@ bool QTextCursorPrivate::movePosition(QTextCursor::MoveOperation op, QTextCursor
break;
}
case QTextCursor::PreviousCharacter:
- newPosition = priv->previousCursorPosition(position, QTextLayout::SkipCharacters);
+ if (mode == QTextCursor::MoveAnchor && position != adjusted_anchor)
+ newPosition = qMin(position, adjusted_anchor);
+ else
+ newPosition = priv->previousCursorPosition(position, QTextLayout::SkipCharacters);
break;
case QTextCursor::Left:
- newPosition = visualMovement ? priv->leftCursorPosition(position)
- : priv->previousCursorPosition(position, QTextLayout::SkipCharacters);
+ if (mode == QTextCursor::MoveAnchor && position != adjusted_anchor)
+ newPosition = visualMovement ? qMax(position, adjusted_anchor)
+ : qMin(position, adjusted_anchor);
+ else
+ newPosition = visualMovement ? priv->leftCursorPosition(position)
+ : priv->previousCursorPosition(position, QTextLayout::SkipCharacters);
break;
case QTextCursor::StartOfWord: {
if (relativePos == 0)
@@ -535,11 +542,18 @@ bool QTextCursorPrivate::movePosition(QTextCursor::MoveOperation op, QTextCursor
break;
}
case QTextCursor::NextCharacter:
- newPosition = priv->nextCursorPosition(position, QTextLayout::SkipCharacters);
+ if (mode == QTextCursor::MoveAnchor && position != adjusted_anchor)
+ newPosition = qMax(position, adjusted_anchor);
+ else
+ newPosition = priv->nextCursorPosition(position, QTextLayout::SkipCharacters);
break;
case QTextCursor::Right:
- newPosition = visualMovement ? priv->rightCursorPosition(position)
- : priv->nextCursorPosition(position, QTextLayout::SkipCharacters);
+ if (mode == QTextCursor::MoveAnchor && position != adjusted_anchor)
+ newPosition = visualMovement ? qMin(position, adjusted_anchor)
+ : qMax(position, adjusted_anchor);
+ else
+ newPosition = visualMovement ? priv->rightCursorPosition(position)
+ : priv->nextCursorPosition(position, QTextLayout::SkipCharacters);
break;
case QTextCursor::NextWord:
case QTextCursor::WordRight: