[QTextCursor] Better use of the cached whiteSpace attribute
In compare to QTextEngine::atSpace(), this also handles the less-common "white spaces" and the exceptional control codes. Change-Id: I52878932926b7f9fe36c9dd01007963b9691fbf0 Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>bb10
parent
c586f958b3
commit
ba5af03a5a
|
|
@ -424,9 +424,9 @@ bool QTextCursorPrivate::movePosition(QTextCursor::MoveOperation op, QTextCursor
|
|||
|
||||
// skip if already at word start
|
||||
QTextEngine *engine = layout->engine();
|
||||
engine->attributes();
|
||||
const QCharAttributes *attributes = engine->attributes();
|
||||
if ((relativePos == blockIt.length() - 1)
|
||||
&& (engine->atSpace(relativePos - 1) || engine->atWordSeparator(relativePos - 1)))
|
||||
&& (attributes[relativePos - 1].whiteSpace || engine->atWordSeparator(relativePos - 1)))
|
||||
return false;
|
||||
|
||||
if (relativePos < blockIt.length()-1)
|
||||
|
|
@ -499,7 +499,7 @@ bool QTextCursorPrivate::movePosition(QTextCursor::MoveOperation op, QTextCursor
|
|||
}
|
||||
case QTextCursor::EndOfWord: {
|
||||
QTextEngine *engine = layout->engine();
|
||||
engine->attributes();
|
||||
const QCharAttributes *attributes = engine->attributes();
|
||||
const int len = blockIt.length() - 1;
|
||||
if (relativePos >= len)
|
||||
return false;
|
||||
|
|
@ -508,7 +508,7 @@ bool QTextCursorPrivate::movePosition(QTextCursor::MoveOperation op, QTextCursor
|
|||
while (relativePos < len && engine->atWordSeparator(relativePos))
|
||||
++relativePos;
|
||||
} else {
|
||||
while (relativePos < len && !engine->atSpace(relativePos) && !engine->atWordSeparator(relativePos))
|
||||
while (relativePos < len && !attributes[relativePos].whiteSpace && !engine->atWordSeparator(relativePos))
|
||||
++relativePos;
|
||||
}
|
||||
newPosition = blockIt.position() + relativePos;
|
||||
|
|
|
|||
|
|
@ -2549,21 +2549,6 @@ bool QTextEngine::atWordSeparator(int position) const
|
|||
return false;
|
||||
}
|
||||
|
||||
bool QTextEngine::atSpace(int position) const
|
||||
{
|
||||
const QChar c = layoutData->string.at(position);
|
||||
switch (c.unicode()) {
|
||||
case QChar::Tabulation:
|
||||
case QChar::Space:
|
||||
case QChar::Nbsp:
|
||||
case QChar::LineSeparator:
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void QTextEngine::setPreeditArea(int position, const QString &preeditText)
|
||||
{
|
||||
if (preeditText.isEmpty()) {
|
||||
|
|
|
|||
|
|
@ -592,7 +592,6 @@ private:
|
|||
|
||||
public:
|
||||
bool atWordSeparator(int position) const;
|
||||
bool atSpace(int position) const;
|
||||
|
||||
QString elidedText(Qt::TextElideMode mode, const QFixed &width, int flags = 0, int from = 0, int count = -1) const;
|
||||
|
||||
|
|
|
|||
|
|
@ -648,10 +648,10 @@ int QTextLayout::nextCursorPosition(int oldPos, CursorMode mode) const
|
|||
while (oldPos < len && d->atWordSeparator(oldPos))
|
||||
oldPos++;
|
||||
} else {
|
||||
while (oldPos < len && !d->atSpace(oldPos) && !d->atWordSeparator(oldPos))
|
||||
while (oldPos < len && !attributes[oldPos].whiteSpace && !d->atWordSeparator(oldPos))
|
||||
oldPos++;
|
||||
}
|
||||
while (oldPos < len && d->atSpace(oldPos))
|
||||
while (oldPos < len && attributes[oldPos].whiteSpace)
|
||||
oldPos++;
|
||||
}
|
||||
|
||||
|
|
@ -679,7 +679,7 @@ int QTextLayout::previousCursorPosition(int oldPos, CursorMode mode) const
|
|||
while (oldPos && !attributes[oldPos].graphemeBoundary)
|
||||
oldPos--;
|
||||
} else {
|
||||
while (oldPos && d->atSpace(oldPos-1))
|
||||
while (oldPos > 0 && attributes[oldPos - 1].whiteSpace)
|
||||
oldPos--;
|
||||
|
||||
if (oldPos && d->atWordSeparator(oldPos-1)) {
|
||||
|
|
@ -687,7 +687,7 @@ int QTextLayout::previousCursorPosition(int oldPos, CursorMode mode) const
|
|||
while (oldPos && d->atWordSeparator(oldPos-1))
|
||||
oldPos--;
|
||||
} else {
|
||||
while (oldPos && !d->atSpace(oldPos-1) && !d->atWordSeparator(oldPos-1))
|
||||
while (oldPos > 0 && !attributes[oldPos - 1].whiteSpace && !d->atWordSeparator(oldPos-1))
|
||||
oldPos--;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue