diff options
author | Frederik Gladhorn <frederik.gladhorn@digia.com> | 2014-06-25 15:27:56 +0200 |
---|---|---|
committer | Frederik Gladhorn <frederik.gladhorn@digia.com> | 2014-08-13 09:07:04 +0200 |
commit | fc931e5595fb63bf1b2f08460046b18f08e20a85 (patch) | |
tree | 7f51c0c283184d49712b21cde2ada38b15631746 /src/gui/accessible | |
parent | 135a2868443a1d9962dece52034db475f3e75036 (diff) |
Accessibility: Fix boundaries for text functions in QLineEdit
Make the functions work consistently. For example asking for the line at
the cursor position when the cursor was at the end returned an empty
line before.
Task-number: QTBUG-38500
Change-Id: I60fc78c7be129a59c83efcfce6d8fdd16f2c3f65
Reviewed-by: Jan Arve Sæther <jan-arve.saether@digia.com>
Diffstat (limited to 'src/gui/accessible')
-rw-r--r-- | src/gui/accessible/qaccessible.cpp | 57 |
1 files changed, 26 insertions, 31 deletions
diff --git a/src/gui/accessible/qaccessible.cpp b/src/gui/accessible/qaccessible.cpp index 7584e23f2e..f41afd52ef 100644 --- a/src/gui/accessible/qaccessible.cpp +++ b/src/gui/accessible/qaccessible.cpp @@ -1917,14 +1917,9 @@ QString QAccessibleTextInterface::textBeforeOffset(int offset, QAccessible::Text { const QString txt = text(0, characterCount()); - if (txt.isEmpty() || offset < 0 || offset > txt.length()) { - *startOffset = *endOffset = -1; + *startOffset = *endOffset = -1; + if (txt.isEmpty() || offset <= 0 || offset > txt.length()) return QString(); - } - if (offset == 0) { - *startOffset = *endOffset = offset; - return QString(); - } QTextBoundaryFinder::BoundaryType type; switch (boundaryType) { @@ -1938,10 +1933,8 @@ QString QAccessibleTextInterface::textBeforeOffset(int offset, QAccessible::Text type = QTextBoundaryFinder::Sentence; break; default: - // in any other case return the whole line - *startOffset = 0; - *endOffset = txt.length(); - return txt; + // return empty, this function currently only supports single lines, so there can be no line before + return QString(); } // keep behavior in sync with QTextCursor::movePosition()! @@ -1977,14 +1970,9 @@ QString QAccessibleTextInterface::textAfterOffset(int offset, QAccessible::TextB { const QString txt = text(0, characterCount()); - if (txt.isEmpty() || offset < 0 || offset > txt.length()) { - *startOffset = *endOffset = -1; - return QString(); - } - if (offset == txt.length()) { - *startOffset = *endOffset = offset; + *startOffset = *endOffset = -1; + if (txt.isEmpty() || offset < 0 || offset >= txt.length()) return QString(); - } QTextBoundaryFinder::BoundaryType type; switch (boundaryType) { @@ -1998,10 +1986,8 @@ QString QAccessibleTextInterface::textAfterOffset(int offset, QAccessible::TextB type = QTextBoundaryFinder::Sentence; break; default: - // in any other case return the whole line - *startOffset = 0; - *endOffset = txt.length(); - return txt; + // return empty, this function currently only supports single lines, so there can be no line after + return QString(); } // keep behavior in sync with QTextCursor::movePosition()! @@ -2009,20 +1995,31 @@ QString QAccessibleTextInterface::textAfterOffset(int offset, QAccessible::TextB QTextBoundaryFinder boundary(type, txt); boundary.setPosition(offset); - while (boundary.toNextBoundary() < txt.length()) { + while (true) { + int toNext = boundary.toNextBoundary(); if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem))) break; + if (toNext < 0 || toNext >= txt.length()) + break; // not found, the boundary might not exist } Q_ASSERT(boundary.position() <= txt.length()); *startOffset = boundary.position(); - while (boundary.toNextBoundary() < txt.length()) { + while (true) { + int toNext = boundary.toNextBoundary(); if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem))) break; + if (toNext < 0 || toNext >= txt.length()) + break; // not found, the boundary might not exist } Q_ASSERT(boundary.position() <= txt.length()); *endOffset = boundary.position(); + if ((*startOffset == -1) || (*endOffset == -1) || (*startOffset == *endOffset)) { + *endOffset = -1; + *startOffset = -1; + } + return txt.mid(*startOffset, *endOffset - *startOffset); } @@ -2037,14 +2034,12 @@ QString QAccessibleTextInterface::textAtOffset(int offset, QAccessible::TextBoun { const QString txt = text(0, characterCount()); - if (txt.isEmpty() || offset < 0 || offset > txt.length()) { - *startOffset = *endOffset = -1; + *startOffset = *endOffset = -1; + if (txt.isEmpty() || offset < 0 || offset > txt.length()) return QString(); - } - if (offset == txt.length()) { - *startOffset = *endOffset = offset; + + if (offset == txt.length() && boundaryType == QAccessible::CharBoundary) return QString(); - } QTextBoundaryFinder::BoundaryType type; switch (boundaryType) { @@ -2058,7 +2053,7 @@ QString QAccessibleTextInterface::textAtOffset(int offset, QAccessible::TextBoun type = QTextBoundaryFinder::Sentence; break; default: - // in any other case return the whole line + // return the whole line *startOffset = 0; *endOffset = txt.length(); return txt; |