summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKonstantin Ritt <ritt.ks@gmail.com>2014-04-04 07:31:24 +0300
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-04-04 19:32:21 +0200
commit330f6e359897f77cf50f67141d09e94c371121ff (patch)
tree239a336b0270b45c682070092e76d9fdf056d1c0 /src
parent47056e78d3d963272e449e8f917ae3208b7aa940 (diff)
QTextLayout: Fix cursor movement from invalid position
Actually guarantee cursor doesn't move in this case for both logical and visual modes (just what the documentation says we already do ;) Change-Id: Iabdca7aa1d205672386a0095e3487e585611cdb5 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/gui/text/qtextengine.cpp15
-rw-r--r--src/gui/text/qtextlayout.cpp5
2 files changed, 13 insertions, 7 deletions
diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp
index 53fd37abba..35950c709b 100644
--- a/src/gui/text/qtextengine.cpp
+++ b/src/gui/text/qtextengine.cpp
@@ -3138,11 +3138,12 @@ int QTextEngine::positionInLigature(const QScriptItem *si, int end,
int QTextEngine::previousLogicalPosition(int oldPos) const
{
const QCharAttributes *attrs = attributes();
- if (!attrs || oldPos < 0)
+ int len = block.isValid() ? block.length() - 1
+ : layoutData->string.length();
+ Q_ASSERT(len <= layoutData->string.length());
+ if (!attrs || oldPos <= 0 || oldPos > len)
return oldPos;
- if (oldPos <= 0)
- return 0;
oldPos--;
while (oldPos && !attrs[oldPos].graphemeBoundary)
oldPos--;
@@ -3224,8 +3225,7 @@ int QTextEngine::beginningOfLine(int lineNum)
int QTextEngine::positionAfterVisualMovement(int pos, QTextCursor::MoveOperation op)
{
- if (!layoutData)
- itemize();
+ itemize();
bool moveRight = (op == QTextCursor::Right);
bool alignRight = isRightToLeft();
@@ -3233,7 +3233,8 @@ int QTextEngine::positionAfterVisualMovement(int pos, QTextCursor::MoveOperation
return moveRight ^ alignRight ? nextLogicalPosition(pos) : previousLogicalPosition(pos);
int lineNum = lineNumberForTextPosition(pos);
- Q_ASSERT(lineNum >= 0);
+ if (lineNum < 0)
+ return pos;
QVector<int> insertionPoints;
insertionPointsForLine(lineNum, insertionPoints);
@@ -3256,6 +3257,8 @@ int QTextEngine::positionAfterVisualMovement(int pos, QTextCursor::MoveOperation
if (lineNum > 0)
return alignRight ? beginningOfLine(lineNum - 1) : endOfLine(lineNum - 1);
}
+
+ break;
}
return pos;
diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp
index 0c9866c6cf..c3cf2e56bb 100644
--- a/src/gui/text/qtextlayout.cpp
+++ b/src/gui/text/qtextlayout.cpp
@@ -674,7 +674,10 @@ int QTextLayout::nextCursorPosition(int oldPos, CursorMode mode) const
int QTextLayout::previousCursorPosition(int oldPos, CursorMode mode) const
{
const QCharAttributes *attributes = d->attributes();
- if (!attributes || oldPos <= 0 || oldPos > d->layoutData->string.length())
+ int len = d->block.isValid() ? d->block.length() - 1
+ : d->layoutData->string.length();
+ Q_ASSERT(len <= d->layoutData->string.length());
+ if (!attributes || oldPos <= 0 || oldPos > len)
return oldPos;
if (mode == SkipCharacters) {