From 5622e32ac9703c9e2c1ce3fb1d0ad77cdbc595f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Mill=C3=A1n=20Soto?= Date: Mon, 6 Jun 2011 15:03:09 +0200 Subject: [PATCH] Changing cursor position in all boundaries Merge-request: 1242 Reviewed-by: Harald Fernengel (cherry picked from commit 97c59df43d821e8e1784749e72f8ee7f90d46da2) Change-Id: Iccb872281a443e57ff3e492911490a8d7495bbdc Reviewed-on: http://codereview.qt.nokia.com/3004 Reviewed-by: Qt Sanity Bot Reviewed-by: Frederik Gladhorn --- src/plugins/accessible/widgets/qaccessiblewidgets.cpp | 2 +- tests/auto/qaccessibility/tst_qaccessibility.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/plugins/accessible/widgets/qaccessiblewidgets.cpp b/src/plugins/accessible/widgets/qaccessiblewidgets.cpp index 34f5be912f..ea5880c846 100644 --- a/src/plugins/accessible/widgets/qaccessiblewidgets.cpp +++ b/src/plugins/accessible/widgets/qaccessiblewidgets.cpp @@ -1435,9 +1435,9 @@ QString QAccessibleTextEdit::textAtOffset(int offset, BoundaryType boundaryType, if (offset >= characterCount()) return QString(); + cursor.setPosition(offset); switch (boundaryType) { case CharBoundary: - cursor.setPosition(offset); *startOffset = cursor.position(); cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor); *endOffset = cursor.position(); diff --git a/tests/auto/qaccessibility/tst_qaccessibility.cpp b/tests/auto/qaccessibility/tst_qaccessibility.cpp index 1ab630d020..9043c4f771 100644 --- a/tests/auto/qaccessibility/tst_qaccessibility.cpp +++ b/tests/auto/qaccessibility/tst_qaccessibility.cpp @@ -1679,6 +1679,8 @@ void tst_QAccessibility::textEditTest() { { QTextEdit edit; + int startOffset; + int endOffset; QString text = "hello world\nhow are you today?\n"; edit.setText(text); edit.show(); @@ -1688,6 +1690,12 @@ void tst_QAccessibility::textEditTest() QCOMPARE(iface->childCount(), 6); QCOMPARE(iface->text(QAccessible::Value, 4), QString("hello world")); QCOMPARE(iface->text(QAccessible::Value, 5), QString("how are you today?")); + QCOMPARE(iface->textInterface()->textAtOffset(8, QAccessible2::WordBoundary, &startOffset, &endOffset), QString("world")); + QCOMPARE(startOffset, 6); + QCOMPARE(endOffset, 11); + QCOMPARE(iface->textInterface()->textAtOffset(14, QAccessible2::LineBoundary, &startOffset, &endOffset), QString("how are you today?")); + QCOMPARE(startOffset, 12); + QCOMPARE(endOffset, 30); QCOMPARE(iface->text(QAccessible::Value, 6), QString()); QCOMPARE(iface->textInterface()->characterCount(), 31); QFontMetrics fm(edit.font());