Update/fix QTextBoundaryFinder simple usage cases in qtbase

Change-Id: I4d3000558bce86e2de3c32247915868ba18fc8b7
Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
This commit is contained in:
Konstantin Ritt 2012-10-08 16:51:41 +03:00 committed by The Qt Project
parent a895359c19
commit 539ef45689
3 changed files with 12 additions and 16 deletions

View File

@ -157,27 +157,27 @@ private:
m_splitter->setPosition(start); m_splitter->setPosition(start);
QScriptAnalysis itemAnalysis = m_analysis[start]; QScriptAnalysis itemAnalysis = m_analysis[start];
if (m_splitter->boundaryReasons() & QTextBoundaryFinder::StartWord) { if (m_splitter->boundaryReasons() & QTextBoundaryFinder::StartOfItem)
itemAnalysis.flags = QScriptAnalysis::Uppercase; itemAnalysis.flags = QScriptAnalysis::Uppercase;
m_splitter->toNextBoundary();
} m_splitter->toNextBoundary();
const int end = start + length; const int end = start + length;
for (int i = start + 1; i < end; ++i) { for (int i = start + 1; i < end; ++i) {
bool atWordStart = false;
bool atWordBoundary = false;
if (i == m_splitter->position()) { if (i == m_splitter->position()) {
if (m_splitter->boundaryReasons() & QTextBoundaryFinder::StartWord if (m_splitter->boundaryReasons() & QTextBoundaryFinder::StartOfItem) {
&& m_analysis[i].flags < QScriptAnalysis::TabOrObject) Q_ASSERT(m_analysis[i].flags < QScriptAnalysis::TabOrObject);
atWordBoundary = true; atWordStart = true;
}
m_splitter->toNextBoundary(); m_splitter->toNextBoundary();
} }
if (m_analysis[i] == itemAnalysis if (m_analysis[i] == itemAnalysis
&& m_analysis[i].flags < QScriptAnalysis::TabOrObject && m_analysis[i].flags < QScriptAnalysis::TabOrObject
&& !atWordBoundary && !atWordStart
&& i - start < MaxItemLength) && i - start < MaxItemLength)
continue; continue;
@ -185,7 +185,7 @@ private:
start = i; start = i;
itemAnalysis = m_analysis[start]; itemAnalysis = m_analysis[start];
if (atWordBoundary) if (atWordStart)
itemAnalysis.flags = QScriptAnalysis::Uppercase; itemAnalysis.flags = QScriptAnalysis::Uppercase;
} }
m_items.append(QScriptItem(start, itemAnalysis)); m_items.append(QScriptItem(start, itemAnalysis));

View File

@ -949,7 +949,7 @@ QPair< int, int > QAccessibleTextWidget::getBoundaries(int offset, BoundaryType
sentenceFinder.setPosition(offsetWithinBlockText); sentenceFinder.setPosition(offsetWithinBlockText);
int prevBoundary = offsetWithinBlockText; int prevBoundary = offsetWithinBlockText;
int nextBoundary = offsetWithinBlockText; int nextBoundary = offsetWithinBlockText;
if (!sentenceFinder.isAtBoundary()) if (!(sentenceFinder.boundaryReasons() & QTextBoundaryFinder::StartOfItem))
prevBoundary = sentenceFinder.toPreviousBoundary(); prevBoundary = sentenceFinder.toPreviousBoundary();
nextBoundary = sentenceFinder.toNextBoundary(); nextBoundary = sentenceFinder.toNextBoundary();
if (nextBoundary != -1) if (nextBoundary != -1)

View File

@ -560,12 +560,8 @@ int QWindowsInputContext::reconvertString(RECONVERTSTRING *reconv)
// Find the word in the surrounding text. // Find the word in the surrounding text.
QTextBoundaryFinder bounds(QTextBoundaryFinder::Word, surroundingText); QTextBoundaryFinder bounds(QTextBoundaryFinder::Word, surroundingText);
bounds.setPosition(pos); bounds.setPosition(pos);
if (bounds.isAtBoundary()) { if (bounds.position() > 0 && !(bounds.boundaryReasons() & QTextBoundaryFinder::StartOfItem))
if (QTextBoundaryFinder::EndWord == bounds.boundaryReasons())
bounds.toPreviousBoundary();
} else {
bounds.toPreviousBoundary(); bounds.toPreviousBoundary();
}
const int startPos = bounds.position(); const int startPos = bounds.position();
bounds.toNextBoundary(); bounds.toNextBoundary();
const int endPos = bounds.position(); const int endPos = bounds.position();