Skip to content

Announce C/C++ completion popup selections to screen readers - #19549

Merged
gtritchie merged 7 commits into
mainfrom
bugfix/cpp-completion-screen-reader
Nov 10, 2026
Merged

gtritchie merged 7 commits into
mainfrom
bugfix/cpp-completion-screen-reader

Conversation

@gtritchie

@gtritchie gtritchie commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Fixes #19532.

C/C++ completion uses its own popup (CppCompletionPopupMenu), not the CompletionList popup that #6167 made screen-reader accessible. Keyboard focus stays in the editor while the user arrows through it, and nothing set the Ace input's aria-activedescendant, so the selected completion wasn't announced.

  • CppCompletionPopupMenu points the editor input's aria-activedescendant at the selected item, through the InputEditorDisplay.setAriaActiveDescendant added for Autocomplete popups not announced by screen readers #6167. As in CompletionList, the first selection is named only after the popup is visible, since VoiceOver ignores a target that is hidden when named. The attribute is cleared when the popup closes or has no results.
  • The list and items get the same roles as the other completion popups (listbox/option with aria-selected; menu/menuitem with aria-current in Safari), and the list is labeled "Completions". Those role choices move from CompletionList into a shared CompletionListAria helper.
  • Completion type icons are marked decorative. SafeHtmlUtil.appendPresentationImage now also writes alt="", which affects the R completion popup's icons too.

This popup still has the gaps #19533 tracks for the R completion and history popups: message-only popups such as "(No matches)" aren't announced, the completion type is shown only by the now-hidden icon, and the signature tooltip (CppCompletionToolTip) isn't linked to the selected item.

Testing

e2e/rstudio/tests/panes/misc/completion_popup_aria.test.ts gains a C++ case: it types s. after a std::string s; in an Rcpp source file, then checks the active option, its role and label, that it was visible when named, that Arrow Down moves it, and that Escape clears it. (A standalone .cpp file only gets completions as an Rcpp or cpp11 source file.) It runs only against macOS sessions with libclang and Rcpp: on the Linux CI runners libclang 18 can't parse the file (#19559), and on the Windows runners no completion popup appears. It fails against the unfixed popup at the aria-activedescendant check.

The spec's tracker for aria-activedescendant writes now records only writes on Ace text inputs, because GWT's MenuBar also sets the attribute on its own never-focused element.

Not yet checked with a screen reader.

CompletionList's role and selected-state choices (listbox/option with
aria-selected, or menu/menuitem with aria-current in Safari) move into
CompletionListAria, so the C/C++ completion popup can apply the same
ones. No behavior change.

Addresses #19532
The C/C++ completion popup leaves keyboard focus in the editor, but
nothing set the Ace input's aria-activedescendant, so screen readers
didn't announce the selected completion. CppCompletionPopupMenu now
gives its list and items the same roles as the other completion
popups, labels the list "Completions", and points the input's
aria-activedescendant at the selected item once the popup is visible,
clearing it when the popup closes or empties. Item icons are marked
presentational.

The e2e tracker for aria-activedescendant writes now records only
writes on the focused element: GWT's MenuBar also sets the attribute on
its own, never-focused element while building items.

Addresses #19532
appendPresentationImage wrote <img role="presentation"> with no alt
attribute. HTML expects alt="" on a decorative image, and a screen
reader that ignores the role can fall back to reading the source.
It renders the completion type icons in both the R and C/C++
completion popups.

Addresses #19532
Drop CppCompletionPopupMenu's onUnload override: ToolbarPopupMenu's
onUnload already deselects the item, and that selection event clears
the editor's aria-activedescendant.

In the test, record aria-activedescendant writes on Ace text inputs
rather than on the focused element, so a write made before focus
arrives is still checked; fail rather than skip when the libclang/Rcpp
probe can't be read; and require alt="" on the completion icons.

Addresses #19532

@gtritchie gtritchie left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review: 7 findings, posted inline except the one below. None are blocking; #1 is a pre-existing GWT hover behavior that the new ARIA state now mirrors.

Stale test header (e2e/rstudio/tests/panes/misc/completion_popup_aria.test.ts:1, :121): the file header still names only #6167 and #6168, and the suite comment says "The editor test creates a file", but the new C++ case (#19532) also creates one.

// through the editor input's aria-activedescendant.
CompletionListAria.setListRole(menuBar_.getElement(),
constants_.completionsListLabel());
addSelectionHandler(event -> setActiveItem(event.getSelectedItem()));

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mouse-out clears aria-activedescendant while the popup is open (plausible; mirrors existing behavior)

GWT MenuBar handles ONMOUSEOUT with itemOver(null, false) -> selectItem(null), and BaseMenuBar.onBrowserEvent passes mouse events through unchanged. This handler then calls setActiveItem(null), so whenever the pointer leaves an item, the editor input loses its active descendant until Arrow Down selects again. Moving between an item's icon and its text also clears and re-sets the attribute, which may make a screen reader repeat the item.

The visual highlight already clears the same way, so this follows an existing quirk rather than adding one. Worth deciding whether the ARIA state should hold the last keyboard selection instead.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving this as is. Confirmed that the fork's itemOver deselects on mouse-out (it only keeps the selection while a submenu is showing). But with nothing selected, Tab or Enter inserts nothing (acceptSelected sees index -1), so announcing no selection matches what the keys will do. Holding the last keyboard selection would announce an item that Tab won't insert. The icon-to-text flicker is the GWT menu hover quirk and only happens with the mouse.

return onSelected_ != null;
}

private void setActiveItem(MenuItem item)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clearing on close relies on a base-class side effect

This works today: ToolbarPopupMenu.onUnload (ToolbarPopupMenu.java:173-178) calls menuBar_.selectItem(null), which fires the SelectionEvent that reaches setActiveItem(null). Nothing in this class guarantees it, though, and announceable_ is never reset on close. CompletionList clears explicitly in its own onUnload (CompletionList.java:162-167); an equivalent override here would keep the guarantee local if the base class changes.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restored the onUnload override in 19d463a; it clears the editor's aria-activedescendant and resets announceable_.

// setPopupPositionAndShow hides the popup while positioning it. VoiceOver
// ignores an active descendant that is hidden when named, and won't
// announce it once shown, so name it after the popup is visible.
private void announceWhenVisible()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Announce-timing logic is duplicated from CompletionList

announceable_, updateActiveDescendant() and the deferred visibility check repeat CompletionList.java:150-197, with different guards (isAttached() there, isShowing() && isVisible() here). Moving this into CompletionListAria alongside the roles would mean a future VoiceOver timing fix is made once, and the popups #19533 tracks could reuse it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving the duplication. The two popups reach the announce step at different points: CompletionList announces once from onLoad, can swap its input through setInput, and checks its own isAttached(); the C++ popup re-announces after every refilter and checks the popup's isShowing() && isVisible(). A shared helper would need hooks for both, to replace about 15 lines in each. #19533's message announcements would likely go through AriaLiveService rather than aria-activedescendant, so I don't expect a third user.

* through the editor input's aria-activedescendant, shared so every such
* popup reads the same way to a screen reader.
*/
public final class CompletionListAria

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shared helper lives in the console package

source/editors/text/cpp now imports this class and ConsoleConstants from views/console just for generic listbox roles and the "Completions" label. A neutral package (e.g. core/client/a11y) would avoid the cross-view dependency.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving it here. The cpp package already depends on console.shell.assist (CompletionManager, CompletionUtils) and console.shell.editor (InputEditorPosition, InputEditorSelection), since C++ completion is built on the console completion framework. Moving this class alone wouldn't remove the cross-view dependency, and the "Completions" label would still come from ConsoleConstants.

ImageResource image)
{
sb.append(SafeHtmlUtil.createOpenTag("img",
"alt", "",

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

appendImage (line 69) is now dead code

On main its only caller was CppCompletionPopupMenu.java:64; this PR switches that call to appendPresentationImage, and git grep 'appendImage(' now finds only the definition. Removing it also keeps future callers from adding icons with no alt text.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in 19d463a.

test.skip(!canComplete, 'C++ completion needs libclang and the Rcpp package');

// C++ completion asks libclang for the members of `s` once `s.` is typed.
// The file must exist on disk, since completion compiles the saved file.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment misstates why the file must be on disk

Completion doesn't compile the saved file: onSourceDocUpdated (SessionClang.cpp:81-98) skips documents without a path and otherwise passes the editor contents to libclang as unsaved files, and CodeCompletion.cpp:546-548 looks up the translation unit by that path. The file on disk is needed so the document has a path that gets compile arguments. Suggested wording: "The file needs a path on disk, which is how it gets Rcpp compile arguments."

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 19d463a with your wording; also updated the file header and the suite's sandbox comment.

- Restore CppCompletionPopupMenu.onUnload, so clearing the editor's
  aria-activedescendant on close doesn't depend on ToolbarPopupMenu
  deselecting the item, and announceable_ resets with it.
- Remove SafeHtmlUtil.appendImage; its only caller now uses
  appendPresentationImage.
- Name #19532 in the test file header, note that the C++ test also
  creates a file, and correct why the .cpp file needs a path on disk.

Addresses #19532
@gtritchie

Copy link
Copy Markdown
Member Author

Re-review of 19d463a: all seven findings are resolved, and the new changes raise nothing new.

Fixed

  • Clearing on close: the onUnload override resets announceable_ and clears the editor's aria-activedescendant before super.onUnload(). The base class's selectItem(null) then clears it again, which is harmless.
  • appendImage: removed, with no remaining GWT references. The ImageResource import is still used by appendPresentationImage.
  • Test comments: the on-disk comment, the file header (now names C/C++ code completion popup not announced by screen readers #19532) and the sandbox comment are updated.

Kept as is, rationale accepted

  • Mouse-out clearing the selection: with nothing selected, acceptSelected sees index -1 and Tab/Enter insert nothing, so announcing no selection matches the keys.
  • Duplicated announce timing: the popups announce at different points and check different visibility conditions, so a shared helper wouldn't save much.
  • CompletionListAria in the console package: on main the cpp package already imports CompletionManager, CompletionUtils, InputEditorPosition and InputEditorSelection from the console packages, so moving it wouldn't remove the dependency.

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

RStudio E2E - all platforms

All tests passed!

#################### 100% pass rate

Passed Failed Skipped Flaky
5444 0 256 5
Platform ✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
✅ auth-teardown 4 0 16 0
✅ desktop-linux 1366 0 46 1
✅ desktop-macos 1361 0 51 2
✅ desktop-windows 1360 0 57 2
✅ server-linux 1305 0 54 0
✅ setup 48 0 32 0

View report online


All platforms - commit 5028bfd97dd928f34708a1e14f570339525894e4 - Run #2164

On the Linux CI runners, libclang 18 fails to parse the Rcpp test file
(#19559), so get_cpp_completions returns null and no popup appears; on
the Windows runners no popup appears within 60 seconds either. The
test passed only on macOS. Skip it unless the R session runs on macOS,
checked from R so the session's platform is tested even against a
remote server.

Addresses #19532
@gtritchie
gtritchie merged commit 20ce844 into main Nov 10, 2026
45 checks passed
@gtritchie
gtritchie deleted the bugfix/cpp-completion-screen-reader branch November 10, 2026 23:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

C/C++ code completion popup not announced by screen readers

1 participant