[frameworks-ktexteditor] [Bug 523883] New: Accessibility: textAtOffset() returns the wrong accessible end offset for lines and words.

"Joanmarie Diggs" <[email protected]> Wed, 05 Aug 2026 08:42:13 +0000
Newsgroups gmane.comp.kde.devel.bugs
Message-ID <[email protected]/>
https://bugs.kde.org/show_bug.cgi?id=523883

            Bug ID: 523883
           Summary: Accessibility: textAtOffset() returns the wrong
                    accessible end offset for lines and words.
    Classification: Frameworks and Libraries
           Product: frameworks-ktexteditor
      Version First unspecified
       Reported In:
          Platform: Other
                OS: Linux
            Status: REPORTED
          Severity: normal
          Priority: NOR
         Component: general
          Assignee: [email protected]
          Reporter: [email protected]
  Target Milestone: ---

Created attachment 194867
  --> https://bugs.kde.org/attachment.cgi?id=194867&action=edit
python reproducer

Steps to reproduce:
1. Launch Kate.
2. Type three short lines, e.g. "Line 1\nLine 2\nLine 3".
3. Run the attached reproducer in a terminal: `python
ktexteditor-atspi-line-boundary-reproducer.py $(pidof kate)`

Expected results: No errors.

Actual results: Errors. See sample output below.

Notes:

As described in the AT-SPI docs, the end offset should correspond to the start
of the next line:
https://docs.gtk.org/atspi2/method.Text.get_string_at_offset.html So the line
at offset 0 should be "Line 1\n" with an end offset of 7; not "Line 1" with an
end offset of 6.

As you'll see in the sample output below, even ignoring the above, the end
offset reported is wrong and doesn't correspond with the returned text. For
instance the reported line at offset 4 is "Line 1" with a start offset of 0
(correct) and an end offset of 10 (which is in "Line 2").  From a code search,
it looks like this line is wrong:
https://invent.kde.org/frameworks/ktexteditor/-/blob/master/src/view/kateviewaccessible.h?plain=1#L238.
The end offset should be the start offset + the line's size; not the offset +
the line's size. (Note that the word boundary seems to have the same bug.)

Impact:

1. Orca's Caret Navigator makes it possible to read content with Orca driving
the navigation. It's intended for web content and also terminals (e.g. to read
the output from a command). But it can be enabled in any application with text.
Because of this bug, Orca-controlled caret navigation is broken in Kate and any
other app that uses KTextEditor.

2. I (Orca maintainer) am adding text-selection support to its Caret Navigator.
Selection (e.g. by line, word, etc.) depend on Orca receiving valid offsets to
use in its calls to set_selection() or add_selection().

Sample output:
============
Document text: 'Line 1\nLine 2\nLine 3'

Atspi.Text.get_string_at_offset(offset, LINE):
  offset  0 'L': text='Line 1', range=0-6, range_text='Line 1';
expected_text='Line 1\n', expected_range=0-7, FAIL
  offset  1 'i': text='Line 1', range=0-7, range_text='Line 1\n';
expected_text='Line 1\n', expected_range=0-7, FAIL
  offset  2 'n': text='Line 1', range=0-8, range_text='Line 1\nL';
expected_text='Line 1\n', expected_range=0-7, FAIL
  offset  3 'e': text='Line 1', range=0-9, range_text='Line 1\nLi';
expected_text='Line 1\n', expected_range=0-7, FAIL
  offset  4 ' ': text='Line 1', range=0-10, range_text='Line 1\nLin';
expected_text='Line 1\n', expected_range=0-7, FAIL
  offset  5 '1': text='Line 1', range=0-11, range_text='Line 1\nLine';
expected_text='Line 1\n', expected_range=0-7, FAIL
  offset  6 '\n': text='Line 1', range=0-12, range_text='Line 1\nLine ';
expected_text='Line 1\n', expected_range=0-7, FAIL
  offset  7 'L': text='Line 2', range=7-13, range_text='Line 2';
expected_text='Line 2\n', expected_range=7-14, FAIL
  offset  8 'i': text='Line 2', range=7-14, range_text='Line 2\n';
expected_text='Line 2\n', expected_range=7-14, FAIL
  offset  9 'n': text='Line 2', range=7-15, range_text='Line 2\nL';
expected_text='Line 2\n', expected_range=7-14, FAIL
  offset 10 'e': text='Line 2', range=7-16, range_text='Line 2\nLi';
expected_text='Line 2\n', expected_range=7-14, FAIL
  offset 11 ' ': text='Line 2', range=7-17, range_text='Line 2\nLin';
expected_text='Line 2\n', expected_range=7-14, FAIL
  offset 12 '2': text='Line 2', range=7-18, range_text='Line 2\nLine';
expected_text='Line 2\n', expected_range=7-14, FAIL
  offset 13 '\n': text='Line 2', range=7-19, range_text='Line 2\nLine ';
expected_text='Line 2\n', expected_range=7-14, FAIL
  offset 14 'L': text='Line 3', range=14-20, range_text='Line 3';
expected_text='Line 3', expected_range=14-20, PASS
  offset 15 'i': text='Line 3', range=14-21, range_text='Line 3';
expected_text='Line 3', expected_range=14-20, FAIL
  offset 16 'n': text='Line 3', range=14-22, range_text='Line 3';
expected_text='Line 3', expected_range=14-20, FAIL
  offset 17 'e': text='Line 3', range=14-23, range_text='Line 3';
expected_text='Line 3', expected_range=14-20, FAIL
  offset 18 ' ': text='Line 3', range=14-24, range_text='Line 3';
expected_text='Line 3', expected_range=14-20, FAIL
  offset 19 '3': text='Line 3', range=14-25, range_text='Line 3';
expected_text='Line 3', expected_range=14-20, FAIL

Expected: LINE extends from the current line start to the following line start.
Result: 19 of 20 character offsets failed
============

-- 
You are receiving this mail because:
You are watching all bug changes.