Repository navigation
Commit 012cfa0
authored
text_view: Expose the rendered body to the accessibility tree (#4056)
## Description
Fixes #3437.
A `TextView` had no accessibility role, so on macOS the native tree
showed the
controls inside and around it but none of its text. A screen reader
could not
read a chat transcript or any other rendered Markdown or HTML.
`TextView` is now an AccessKit `Document` whose synthetic `TextRun`
children
carry the rendered text. AccessKit gives a client a node's text only
through
such runs (`supports_text_ranges`), which then answer `AXValue`,
`AXNumberOfCharacters` and the text-range calls on macOS, the Text
interface on
AT-SPI and the Text pattern on UIA. The runs reuse the Input's
`A11yTextRuns`,
so no separate parser is involved:
- The text is `TextViewState::rendered_text`, the same string plain copy
produces, so it follows `set_text` and `push_str` as their parses land.
- Runs are captured in prepaint and only while
`window.is_a11y_active()`, so
views without an assistive client do no extra work. The state keeps them
until the revision, select-all or scale changes, so a long transcript is
not
split into characters again on every frame.
- `A11yTextRuns` takes an optional selection now. A read-only view with
nothing
selected reports no caret. A select-all is reported over the whole text.
The Input still passes its selection as before.
- Controls inside the view (code block actions, images with labels) stay
in the
tree. AccessKit excludes non-run children from the document's text.
This changes `gpui-base`, because the issue is in
`crates/base/src/text/text_view.rs`.
### Not covered yet
- Paragraph, heading, link, list and code semantics. The body is exposed
as
plain text, one run per line.
- Partial selections. The view has no mapping from its selection to
rendered-text offsets yet, so it reports none rather than a wrong one.
- Character geometry. Runs carry no bounds, so hit testing a point in
the text
lands on the document.
Prepared with AI assistance. I reviewed the generated code.
## How to Test
```sh
cargo test -p gpui-base --lib -- accessibility_text_follows a11y_text
cargo test -p gpui-kit --features test-support,gpui-fast --test integration -- a11y_text
```
- `accessibility_text_follows_the_rendered_text` checks that the runs
hold the
rendered text (not the source), follow `push_str` and `set_text`, and
report
select-all, and that unchanged text reuses its runs.
- `text_view_body_is_in_the_accessibility_tree` renders a selectable
`TextView` beside a label in a window and checks the tree. It is
`gpui-fast`
only, like the existing test there, because only that backend's test
window
builds a tree. It fails when the role is removed.
- All `gpui-base` `input::` tests (488) pass after the `A11yTextRuns`
change.
- `cargo clippy -p gpui-base -p gpui-kit -- --deny warnings` passes.
`--all-targets` reports a redundant clone in `text/inline.rs` tests,
which is
also on `main`.
Not yet verified with VoiceOver in a native window.
## Checklist
- [x] I have read the [CONTRIBUTING](../CONTRIBUTING.md) document and
followed the guidelines.
- [x] Reviewed the changes in this PR and confirmed AI generated code
(If any) is accurate.
- [ ] Passed `cargo run` for story tests related to the changes.
- [ ] Tested macOS, Windows and Linux platforms performance (if the
change is platform-specific)1 parent 8515630 commit 012cfa0
5 files changed
Lines changed: 217 additions & 30 deletions
File tree
- crates
- base/src
- input
- base
- text
- kit/tests/integration
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
| 43 | + | |
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
70 | | - | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
71 | 72 | | |
72 | 73 | | |
73 | 74 | | |
| |||
78 | 79 | | |
79 | 80 | | |
80 | 81 | | |
81 | | - | |
82 | | - | |
| 82 | + | |
| 83 | + | |
83 | 84 | | |
84 | 85 | | |
85 | | - | |
| 86 | + | |
86 | 87 | | |
87 | 88 | | |
88 | 89 | | |
| |||
118 | 119 | | |
119 | 120 | | |
120 | 121 | | |
121 | | - | |
122 | | - | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
123 | 125 | | |
124 | 126 | | |
125 | 127 | | |
126 | | - | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
127 | 141 | | |
128 | 142 | | |
129 | 143 | | |
130 | | - | |
131 | | - | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
132 | 150 | | |
133 | | - | |
| 151 | + | |
134 | 152 | | |
135 | 153 | | |
136 | 154 | | |
| |||
140 | 158 | | |
141 | 159 | | |
142 | 160 | | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
149 | 167 | | |
150 | 168 | | |
151 | 169 | | |
152 | 170 | | |
153 | 171 | | |
154 | 172 | | |
155 | | - | |
156 | | - | |
157 | | - | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
158 | 176 | | |
159 | 177 | | |
160 | 178 | | |
| |||
289 | 307 | | |
290 | 308 | | |
291 | 309 | | |
292 | | - | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
293 | 319 | | |
294 | 320 | | |
295 | 321 | | |
| |||
306 | 332 | | |
307 | 333 | | |
308 | 334 | | |
309 | | - | |
| 335 | + | |
310 | 336 | | |
311 | 337 | | |
312 | 338 | | |
| |||
333 | 359 | | |
334 | 360 | | |
335 | 361 | | |
336 | | - | |
| 362 | + | |
337 | 363 | | |
338 | 364 | | |
339 | 365 | | |
340 | 366 | | |
341 | 367 | | |
342 | 368 | | |
343 | 369 | | |
344 | | - | |
345 | | - | |
| 370 | + | |
| 371 | + | |
346 | 372 | | |
347 | 373 | | |
348 | 374 | | |
| |||
359 | 385 | | |
360 | 386 | | |
361 | 387 | | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
362 | 395 | | |
363 | 396 | | |
364 | 397 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
23 | | - | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
151 | 152 | | |
152 | 153 | | |
153 | 154 | | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
154 | 158 | | |
155 | 159 | | |
156 | 160 | | |
| |||
232 | 236 | | |
233 | 237 | | |
234 | 238 | | |
| 239 | + | |
235 | 240 | | |
236 | 241 | | |
237 | 242 | | |
| |||
675 | 680 | | |
676 | 681 | | |
677 | 682 | | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
678 | 707 | | |
679 | 708 | | |
680 | 709 | | |
| |||
2327 | 2356 | | |
2328 | 2357 | | |
2329 | 2358 | | |
| 2359 | + | |
| 2360 | + | |
| 2361 | + | |
| 2362 | + | |
| 2363 | + | |
| 2364 | + | |
| 2365 | + | |
| 2366 | + | |
| 2367 | + | |
| 2368 | + | |
| 2369 | + | |
| 2370 | + | |
| 2371 | + | |
| 2372 | + | |
| 2373 | + | |
| 2374 | + | |
| 2375 | + | |
| 2376 | + | |
| 2377 | + | |
| 2378 | + | |
| 2379 | + | |
| 2380 | + | |
| 2381 | + | |
| 2382 | + | |
| 2383 | + | |
| 2384 | + | |
| 2385 | + | |
| 2386 | + | |
| 2387 | + | |
| 2388 | + | |
| 2389 | + | |
| 2390 | + | |
| 2391 | + | |
2330 | 2392 | | |
2331 | 2393 | | |
2332 | 2394 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
733 | 734 | | |
734 | 735 | | |
735 | 736 | | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
736 | 740 | | |
737 | 741 | | |
738 | 742 | | |
| |||
829 | 833 | | |
830 | 834 | | |
831 | 835 | | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
832 | 852 | | |
833 | 853 | | |
834 | 854 | | |
| |||
1084 | 1104 | | |
1085 | 1105 | | |
1086 | 1106 | | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
1087 | 1114 | | |
1088 | 1115 | | |
1089 | 1116 | | |
1090 | 1117 | | |
| 1118 | + | |
1091 | 1119 | | |
1092 | 1120 | | |
1093 | 1121 | | |
| |||
0 commit comments