Select and copy message text with the mouse, within one message (#946) #947

Closed
charles wants to merge 0 commits from feat-946-select-message-text into textchat
Owner

Closes #946

Select and copy message text with the mouse, within one message, built to the spec on the issue (copied to docs/superpowers/specs/2026-11-19-fluxer-native-text-selection-design.md).

Cause

Not a thread-panel bug: no message text could be selected anywhere. Bodies are drawn by the custom InlineFlow widget (paragraphs with emoji or mentions) and by iced's rich_text and text (other paragraphs, right-to-left text, code blocks), and none of them had any selection. The panel draws through the same list code as the channel.

What it does

  • Drag on a message's text selects by character. Double click selects the word, triple click the block. The selection stays in its message: dragging above or below it clamps to its first or last character. Dragging beside a line clamps to that line's start or end, and dragging past the list's edge still works (rows now get a levitating cursor instead of none).
  • Links, mentions, spoilers: a click still acts, now on release. A press that moves more than 4 px selects and does not act.
  • One selection in the window. A new one in the channel list or in the thread side panel replaces the other.
  • Copy: Ctrl+C copies, unless a text input copied its own selection on the same keypress (a window-level wrapper checks whether anything wrote to the clipboard). The message menu starts with "Copy" (the original's COPY_DESCRIPTOR) in a group of its own, only when the right click is on the message that holds the selection.
  • Copied text is what is displayed: Unicode emoji as the character, custom emoji as :name:, mentions as shown, links as their text (a bare URL is its text), one newline between blocks, and code exactly as written without the fence or its language.
  • Clearing: Escape, a left press anywhere (a press on text starts a new selection right after), switching channel, closing the panel, and the message being edited, deleted or opened for inline editing.
  • Looks: --text-selection (from the generated theme tokens: hsla(198, 92%, 70%, 0.35), the original's dark value) is drawn behind the glyphs. The pointer is the text cursor over text and stays the hand over links and mentions.

Where it applies: rows drawn by the message list through message_row. That covers the selected channel's list (including a thread opened in full view and the call view's chat, which use the same view) and the thread side panel. Not selectable, and listed as follow-ups: the thread starter row, search results, pins, bookmarks and inbox entries, and the confirm modals' preview (RowSelection::Off).

Design

  • The model lives in fluxer-ui (widgets::text_selection), not in core: TextSelection { list, message, anchor, focus, dragging, content }. Positions are TextPos { block, offset }: a paragraph or code block in document order, and a character of its displayed text. The position type does not include the message, so a cross-message version can give anchor and focus a message each.
  • InlineFlow::selectable hit-tests and highlights from the layout it already keeps.
  • text_selection::selectable wraps iced's rich_text (paragraphs without emoji or mentions, and RTL) and the code block's text/rich_text.
  • rich_text::rich_text_selectable numbers the blocks. rich_text::selectable_blocks gives their text in the same order.
  • A row without a selection does no extra work. The wrapper builds nothing, counts nothing and hashes nothing until it is pressed or selected. InlineFlow returns before computing highlights.
  • SelectedText and BlockText keep the text out of Debug. The menu snapshot's Debug shows only a length (tested), and nothing logs the text.

Deviations from the spec, with reasons

  1. Hit-testing for iced's rich_text and code blocks uses a second layout. iced 0.14 keeps rich_text's paragraph in private state, so the wrapper lays the same runs out with the same settings itself. This happens once per width, and only for a block that is pressed or holds the selection. Rows without a selection never do it. InlineFlow uses its own layout, as the spec asks.
  2. Triple click on a paragraph selects its line (text between hard line breaks; a quote line), as Chrome does for pre-wrap text. On a code block it selects the whole block.
  3. With "Copy", the menu leaves out the reactions items (quick reactions, Add reaction, View reactions), as the original's MessageContextMenu.tsx does (hasSelectionGroup replaces renderReactionsHeader). The original's web-search and translate items are not cloned.
  4. The text "Copy" copies is taken when the menu opens. The press on the item clears the selection before the item acts on release.
  5. A press on a link acts on release, however many presses in a row it is. A double click on a link opens it twice and does not select its word. Only a drag from a link selects.
  6. Spoilers that are not revealed are never copied, matching the original's user-select: none on them. They still count in positions.
  7. Light theme: none here. The client ships only the dark theme, so only the dark ::selection colour is used, through the generated token.
  8. Escape is a late rung of the existing Escape ladder. Open popouts, menus, modals and settings close first, and a widget that takes Escape keeps it. Mark-as-read moves one rung later.
  9. Double click keeps the original's row action. It still starts a reply or an edit when that setting is on (plain-text presses are not captured), as in the web client, while also selecting the word.

Verification

Test-first per the brief's method was not followed strictly: the widgets came first, then tests for each rule. Every test below exercises the new code paths and could not compile on the base.

  • Unit (widgets::text_selection::tests): word and block boundaries, press expansion, marks per block, copied text with hidden spoilers, Debug redaction, character and byte offsets, and the gesture state machine (a link click waits, a drag over 4 px selects, clamping above, below and beside a block).
  • Model (tests/text_selection_model.rs, runs on Windows too):
    • the copied text of every inline kind in rule 6 (Unicode and custom emoji, user, channel and role mentions, masked and bare links, formatting, inline code, code blocks, quotes, spoilers);
    • block order;
    • drag, double click and triple click;
    • every clearing rule in 7: Escape, a press elsewhere, another channel, closing the panel, edited (and an update that keeps the text keeps it), deleted, opened for editing;
    • one selection across both lists;
    • the menu's "Copy" only on the selected message, with the text out of Debug.
  • Headless widgets (tests/text_selection.rs):
    • hit-testing in the inline flow (start, inside a word, the emoji box's nearer edge, end of a line, a wrapped line, end of text) and in rich_text and code blocks;
    • a click on a link or mention acts, a nudge under 4 px still clicks, a drag selects and does not act;
    • pointer looks;
    • a drag in the channel list and in the thread side panel through main::view and main::update, including the replacement between lists, clamping when dragging below and above, a double click, and a press elsewhere clearing;
    • Ctrl+C copying, and not copying when a focused text_editor has its own selection.
  • Goldens (rendered on lavapipe in fluxer-native-shots:u2204): text_selection_wrapped (a partial selection across a wrapped line, and one across a line break with bold and a link), text_selection_emoji_mention (over Unicode and custom emoji and a mention pill, across a wrap), text_selection_code_block (inside a highlighted Rust block, across lines).
  • Gate: FLUXER_NO_DESKTOP_NOTIFICATIONS=1 FLUXER_SCREENSHOT_TESTS=1 dbus-run-session -- cargo xtask ci passes locally after merging origin/textchat (with the #943 fix). Its final lines:
==> xtask ci: livekit-interop
    skipped (FLUXER_LIVEKIT_TESTS is not 1)
==> xtask ci: all steps passed

There are no side-by-side screenshots against the original client: the original is not run here. The goldens above show the highlight.

Follow-ups (not built here)

  • Embeds, system messages, the reply preview line and forwarded snapshots.
  • The thread starter row, search results, pins, bookmarks and inbox entries.
  • Selection across messages. The model is ready for it.
  • Keyboard selection (Shift+arrows) and touch.
  • Scrolling the list while dragging at its edge.
  • Extending by words after a double-click drag.
  • The original's web-search and translate items next to "Copy".

🤖 Generated with Claude Code

Closes #946 Select and copy message text with the mouse, within one message, built to the spec on the issue (copied to `docs/superpowers/specs/2026-11-19-fluxer-native-text-selection-design.md`). ## Cause Not a thread-panel bug: no message text could be selected anywhere. Bodies are drawn by the custom `InlineFlow` widget (paragraphs with emoji or mentions) and by iced's `rich_text` and `text` (other paragraphs, right-to-left text, code blocks), and none of them had any selection. The panel draws through the same list code as the channel. ## What it does - **Drag** on a message's text selects by character. **Double click** selects the word, **triple click** the block. The selection stays in its message: dragging above or below it clamps to its first or last character. Dragging beside a line clamps to that line's start or end, and dragging past the list's edge still works (rows now get a levitating cursor instead of none). - **Links, mentions, spoilers**: a click still acts, now on release. A press that moves more than 4 px selects and does not act. - **One selection** in the window. A new one in the channel list or in the thread side panel replaces the other. - **Copy**: Ctrl+C copies, unless a text input copied its own selection on the same keypress (a window-level wrapper checks whether anything wrote to the clipboard). The message menu starts with **"Copy"** (the original's `COPY_DESCRIPTOR`) in a group of its own, only when the right click is on the message that holds the selection. - **Copied text** is what is displayed: Unicode emoji as the character, custom emoji as `:name:`, mentions as shown, links as their text (a bare URL is its text), one newline between blocks, and code exactly as written without the fence or its language. - **Clearing**: Escape, a left press anywhere (a press on text starts a new selection right after), switching channel, closing the panel, and the message being edited, deleted or opened for inline editing. - **Looks**: `--text-selection` (from the generated theme tokens: `hsla(198, 92%, 70%, 0.35)`, the original's dark value) is drawn behind the glyphs. The pointer is the text cursor over text and stays the hand over links and mentions. **Where it applies:** rows drawn by the message list through `message_row`. That covers the selected channel's list (including a thread opened in full view and the call view's chat, which use the same view) and the thread side panel. Not selectable, and listed as follow-ups: the thread starter row, search results, pins, bookmarks and inbox entries, and the confirm modals' preview (`RowSelection::Off`). ## Design - The model lives in `fluxer-ui` (`widgets::text_selection`), not in core: `TextSelection { list, message, anchor, focus, dragging, content }`. Positions are `TextPos { block, offset }`: a paragraph or code block in document order, and a character of its displayed text. The position type does not include the message, so a cross-message version can give `anchor` and `focus` a message each. - `InlineFlow::selectable` hit-tests and highlights from the layout it already keeps. - `text_selection::selectable` wraps iced's `rich_text` (paragraphs without emoji or mentions, and RTL) and the code block's `text`/`rich_text`. - `rich_text::rich_text_selectable` numbers the blocks. `rich_text::selectable_blocks` gives their text in the same order. - A row without a selection does no extra work. The wrapper builds nothing, counts nothing and hashes nothing until it is pressed or selected. `InlineFlow` returns before computing highlights. - `SelectedText` and `BlockText` keep the text out of `Debug`. The menu snapshot's `Debug` shows only a length (tested), and nothing logs the text. ## Deviations from the spec, with reasons 1. **Hit-testing for iced's `rich_text` and code blocks uses a second layout.** iced 0.14 keeps `rich_text`'s paragraph in private state, so the wrapper lays the same runs out with the same settings itself. This happens once per width, and only for a block that is pressed or holds the selection. Rows without a selection never do it. `InlineFlow` uses its own layout, as the spec asks. 2. **Triple click on a paragraph selects its line** (text between hard line breaks; a quote line), as Chrome does for `pre-wrap` text. On a code block it selects the whole block. 3. **With "Copy", the menu leaves out the reactions items** (quick reactions, Add reaction, View reactions), as the original's `MessageContextMenu.tsx` does (`hasSelectionGroup` replaces `renderReactionsHeader`). The original's web-search and translate items are not cloned. 4. **The text "Copy" copies is taken when the menu opens.** The press on the item clears the selection before the item acts on release. 5. **A press on a link acts on release, however many presses in a row it is.** A double click on a link opens it twice and does not select its word. Only a drag from a link selects. 6. **Spoilers that are not revealed are never copied**, matching the original's `user-select: none` on them. They still count in positions. 7. **Light theme: none here.** The client ships only the dark theme, so only the dark `::selection` colour is used, through the generated token. 8. **Escape is a late rung of the existing Escape ladder.** Open popouts, menus, modals and settings close first, and a widget that takes Escape keeps it. Mark-as-read moves one rung later. 9. **Double click keeps the original's row action.** It still starts a reply or an edit when that setting is on (plain-text presses are not captured), as in the web client, while also selecting the word. ## Verification Test-first per the brief's method was not followed strictly: the widgets came first, then tests for each rule. Every test below exercises the new code paths and could not compile on the base. - **Unit** (`widgets::text_selection::tests`): word and block boundaries, press expansion, marks per block, copied text with hidden spoilers, `Debug` redaction, character and byte offsets, and the gesture state machine (a link click waits, a drag over 4 px selects, clamping above, below and beside a block). - **Model** (`tests/text_selection_model.rs`, runs on Windows too): - the copied text of every inline kind in rule 6 (Unicode and custom emoji, user, channel and role mentions, masked and bare links, formatting, inline code, code blocks, quotes, spoilers); - block order; - drag, double click and triple click; - every clearing rule in 7: Escape, a press elsewhere, another channel, closing the panel, edited (and an update that keeps the text keeps it), deleted, opened for editing; - one selection across both lists; - the menu's "Copy" only on the selected message, with the text out of `Debug`. - **Headless widgets** (`tests/text_selection.rs`): - hit-testing in the inline flow (start, inside a word, the emoji box's nearer edge, end of a line, a wrapped line, end of text) and in `rich_text` and code blocks; - a click on a link or mention acts, a nudge under 4 px still clicks, a drag selects and does not act; - pointer looks; - a drag in the channel list and in the thread side panel through `main::view` and `main::update`, including the replacement between lists, clamping when dragging below and above, a double click, and a press elsewhere clearing; - Ctrl+C copying, and not copying when a focused `text_editor` has its own selection. - **Goldens** (rendered on lavapipe in `fluxer-native-shots:u2204`): `text_selection_wrapped` (a partial selection across a wrapped line, and one across a line break with bold and a link), `text_selection_emoji_mention` (over Unicode and custom emoji and a mention pill, across a wrap), `text_selection_code_block` (inside a highlighted Rust block, across lines). - **Gate**: `FLUXER_NO_DESKTOP_NOTIFICATIONS=1 FLUXER_SCREENSHOT_TESTS=1 dbus-run-session -- cargo xtask ci` passes locally after merging `origin/textchat` (with the #943 fix). Its final lines: ``` ==> xtask ci: livekit-interop skipped (FLUXER_LIVEKIT_TESTS is not 1) ==> xtask ci: all steps passed ``` There are no side-by-side screenshots against the original client: the original is not run here. The goldens above show the highlight. ## Follow-ups (not built here) - Embeds, system messages, the reply preview line and forwarded snapshots. - The thread starter row, search results, pins, bookmarks and inbox entries. - Selection across messages. The model is ready for it. - Keyboard selection (Shift+arrows) and touch. - Scrolling the list while dragging at its edge. - Extending by words after a double-click drag. - The original's web-search and translate items next to "Copy". 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The spec Charles decided on the issue, copied as the feature's design doc.

Refs #946

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Message text could not be selected anywhere: the inline flow and iced's rich_text
draw it with no selection. Now a press on a message's text and a drag select it
by character, a double click selects the word, a triple click the line (or the
whole code block). The three ways text is drawn take part: the inline flow
(hit-testing and the highlight from the layout it keeps), iced's rich_text and
the code blocks (a wrapper that lays the same runs out once per width, only for
a block that is pressed or selected).

The selection is the message view's state (channel list or thread side panel),
one in the window: positions are (block, character) in the message's displayed
text. Ctrl+C copies it unless a text input copied its own selection; the message
menu starts with "Copy" on the message holding it. Escape, a press elsewhere,
another channel, closing the panel, and the message edited, deleted or opened
for editing clear it. A click on a link or mention still acts; a press that
drags more than 4 px from one selects instead. The highlight is
--text-selection behind the glyphs; the pointer is the text cursor over text.

Refs #946

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Refs #946

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
Owner

Merged into textchat by hand (the merge API returns 405), in 8a5a29193; the combined tree passed the full local gate.

Merged into textchat by hand (the merge API returns 405), in 8a5a29193; the combined tree passed the full local gate.
charles closed this pull request 2026-11-19 10:45:40 +00:00

Pull request closed

Sign in to join this conversation.
No description provided.