summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederik Gladhorn <gladhorn@kde.org>2014-01-12 00:51:04 (GMT)
committerFrederik Gladhorn <gladhorn@kde.org>2014-01-19 16:32:06 (GMT)
commitdbc4c0709a7832ff7c8a17009ece346fbe610a6c (patch)
treede7324523ff423bce2d275d01f53e5673ac6dd0c
parentafe543e710305ca7795309031dba04a4ed763932 (diff)
Simplify accessibility cursor updates
-rw-r--r--src/view/kateviewaccessible.h34
-rw-r--r--src/view/kateviewinternal.cpp12
2 files changed, 19 insertions, 27 deletions
diff --git a/src/view/kateviewaccessible.h b/src/view/kateviewaccessible.h
index 98c7fd5..f21cf15 100644
--- a/src/view/kateviewaccessible.h
+++ b/src/view/kateviewaccessible.h
@@ -129,7 +129,7 @@ public:
virtual int cursorPosition() const
{
KTextEditor::Cursor c = view()->getCursor();
- return positionFromCursor(c);
+ return positionFromCursor(view(), c);
}
virtual int offsetAtPoint(const QPoint & /*point*/) const
{
@@ -154,8 +154,8 @@ public:
return;
}
KTextEditor::Range range = view()->view()->selectionRange();
- *startOffset = positionFromCursor(range.start());
- *endOffset = positionFromCursor(range.end());
+ *startOffset = positionFromCursor(view(), range.start());
+ *endOffset = positionFromCursor(view(), range.end());
}
virtual int selectionCount() const
@@ -182,8 +182,20 @@ public:
return view()->view()->document()->text().mid(startOffset, endOffset - startOffset);
}
+ static int positionFromCursor(KateViewInternal *view, const KTextEditor::Cursor &cursor)
+ {
+ int pos = 0;
+ for (int line = 0; line < cursor.line(); ++line) {
+ // length of the line plus newline
+ pos += view->view()->document()->line(line).size() + 1;
+ }
+ pos += cursor.column();
+
+ return pos;
+ }
+
private:
- KateViewInternal *view() const
+ inline KateViewInternal *view() const
{
return static_cast<KateViewInternal *>(object());
}
@@ -204,18 +216,6 @@ private:
return KTextEditor::Cursor(line, position);
}
- int positionFromCursor(const KTextEditor::Cursor &cursor) const
- {
- int pos = 0;
- for (int line = 0; line < cursor.line(); ++line) {
- // length of the line plus newline
- pos += view()->view()->document()->line(line).size() + 1;
- }
- pos += cursor.column();
-
- return pos;
- }
-
QString textLine(int shiftLines, int offset, int *startOffset, int *endOffset) const
{
KTextEditor::Cursor pos = cursorFromInt(offset);
@@ -223,7 +223,7 @@ private:
if (shiftLines) {
pos.setLine(pos.line() + shiftLines);
}
- *startOffset = positionFromCursor(pos);
+ *startOffset = positionFromCursor(view(), pos);
QString line = view()->view()->document()->line(pos.line()) + QLatin1Char('\n');
*endOffset = *startOffset + line.length();
return line;
diff --git a/src/view/kateviewinternal.cpp b/src/view/kateviewinternal.cpp
index b6d4f09..d0b0149 100644
--- a/src/view/kateviewinternal.cpp
+++ b/src/view/kateviewinternal.cpp
@@ -3518,16 +3518,8 @@ void KateViewInternal::cursorMoved()
m_view->updateRangesIn(KTextEditor::Attribute::ActivateCaretIn);
#ifndef QT_NO_ACCESSIBILITY
- if (QAccessible::isActive()) {
- QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(this);
- if (iface) {
- QAccessibleTextInterface *textInterface = iface->textInterface();
- if (textInterface) {
- QAccessibleTextCursorEvent ev(this, textInterface->cursorPosition());
- QAccessible::updateAccessibility(&ev);
- }
- }
- }
+ QAccessibleTextCursorEvent ev(this, KateViewAccessible::positionFromCursor(this, m_cursor));
+ QAccessible::updateAccessibility(&ev);
#endif
}