Skip to content

Allow copying every monospace text in a message with screen readers - #2062

Open
mehranlatifi83 wants to merge 1 commit into
DrKLO:masterfrom
mehranlatifi83:fix/talkback-mono-text-not-copyable
Open

mehranlatifi83 wants to merge 1 commit into
DrKLO:masterfrom
mehranlatifi83:fix/talkback-mono-text-not-copyable

Conversation

@mehranlatifi83

@mehranlatifi83 mehranlatifi83 commented Sep 4, 2026 •

Copy link
Copy Markdown

Problem

Monospace text is copied by long pressing it, and long code blocks have a copy button. A message can contain many of both, in its text and caption.

TalkBack only had one "Copy code" action, which copied the first code block in the message text and did not say what it would copy. Other code blocks, monospace text, and anything in a caption could not be copied.

Fix

In ChatMessageCell, add a separate copy action for each code block and each monospace run, with the text to be copied in the action label. They are listed after the message's other actions, and use the same code paths as the long press and the copy button. Nothing is offered where copying is not allowed (as on screen).

Action ids come from a fixed list of resource ids (R.id.acc_action_...). TalkBack only lists a custom action when its id is above 0x01FFFFFF (AccessibilityNodeInfoUtils.isCustomAction), so ids from View.generateViewId() would never be shown. Short code blocks without a copy button, and code blocks and monospace runs in rich messages (RichMessageLayout.getAccessibilityCopyableTexts), are offered too.

Testing

With TalkBack on, send a message with two code blocks and some monospace text, and open its actions.

Before: one "Copy code" action for the first block only. After: one action per block and run, each naming what it copies.

@mehranlatifi83
mehranlatifi83 force-pushed the fix/talkback-mono-text-not-copyable branch from 45fd8d5 to 3e8efcd Compare September 18, 2026 09:50
@mehranlatifi83
mehranlatifi83 force-pushed the fix/talkback-mono-text-not-copyable branch from 3e8efcd to 2f8c5a1 Compare September 27, 2026 10:45
A run of monospace text is copied by holding a press on it, and a block
of code long enough to be given a copy button is copied by pressing that.
A message can carry any number of both, in its text and in its caption.

What a screen reader had was a single action called "Copy code", which
copied whichever block of code came first in the text of the message.
Every other block, every run of monospace text, and everything in a
caption could not be copied at all, and the one action that did work did
not say what it would copy.

Give each of them an action of its own and put what it would copy in the
name of the action, so which is which is known without pressing one and
looking at the clipboard afterwards. They come after everything else the
message offers.

Copying goes through the very paths a press takes, so the same thing is
put on the clipboard and the same word is said back about it. Where
copying is not allowed nothing is offered, which is what the screen does:
the button under a block of code is not drawn, and a press held on a run
of monospace text quietly does nothing.

The ids of the actions are taken from a fixed list of resource ids. Ids
handed out for views are small numbers, and TalkBack lists a custom
action only when its id is above 0x01FFFFFF, so actions with such ids
were never shown. A block of code too short to get a copy button is
offered as well, and so are the code and the monospace runs of a
message laid out in blocks, which a tap copies.
@mehranlatifi83
mehranlatifi83 force-pushed the fix/talkback-mono-text-not-copyable branch 2 times, most recently from 72d527f to 417e410 Compare October 1, 2026 23:01
@mehranlatifi83 mehranlatifi83 changed the title Let every piece of monospace text on a message be copied Oct 1, 2026
@mehranlatifi83
mehranlatifi83 force-pushed the fix/talkback-mono-text-not-copyable branch from 417e410 to bf1d752 Compare October 3, 2026 17:51
@mehranlatifi83
mehranlatifi83 force-pushed the fix/talkback-mono-text-not-copyable branch from bf1d752 to 23c858a Compare October 13, 2026 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant