Skip to content

The desktop app shows formatted text and writes it, with mentions - #186

Merged
pitis merged 3 commits into
mainfrom
feat/desktop-formatted-text
Nov 14, 2026
Merged

pitis merged 3 commits into
mainfrom
feat/desktop-formatted-text

Conversation

@pitis

@pitis pitis commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

What changed

Showing (text.rs, actions/view.rs), after the Mac app's MessageText.swift:

  • Bubbles and quotes draw bold, italic, strikethrough and monospace (the theme's monospace font), and mentions as a bold "@name" in the styles around them ("@you" for us).
  • A spoiler is covered by a block of the text's colour over the bubble's, until its message is clicked ("Click to reveal", as the Mac's .help). While it is covered, the text can't be selected, so the hidden words can't be copied; Copy still copies them, as on the Mac (revealSpoilers: true). Quotes keep their spoilers covered. The block is painted over the text, not as a text colour, because emoji ignore text colours. What a covered spoiler hides isn't read out to assistive technology either: the row's label says "■■■■".
  • The chat list's preview, and the reply and edit bars, stay plain text with "@name" and "■■■■", as on the Mac (unchanged).

Writing (new app/compose.rs and app/compose/view.rs), after ComposerText.swift, ComposerField.swift and the compose-formatting and mention-picker specs:

  • ⌘B bold, ⌘I italic, ⇧⌘X strikethrough, ⌘E monospace, ⇧⌘B spoiler (Ctrl on Windows and Linux) style the selection, or turn the style off if all of it already has it. With nothing selected, they apply to what you type next. The composer's right-click menu has the same under Format, followed by Cut, Copy, Paste and Select All.
  • Typed text takes the styles of the character before it (the Mac's typing attributes). Replacing a selection keeps the styles of its first character. When an input method commits its whole text, the text it didn't change keeps its styles.
  • In a group, "@" at the start or after a space, plus the start of any word in a name, offers matching members: up to 8, sorted by name, with 22pt pictures, leaving us out. ↑/↓ choose, ↩ or Tab picks, a click picks, and Esc closes the list until another "@word" is typed (before Esc can drop a reply). The picked member becomes the field's own inline token "@name", in the accent colour, followed by a space.
  • Sending and saving an edit pass the ranges through send_text/edit, measured in UTF-16. Each mention goes out as U+FFFC under a mention range. The text is trimmed, and touching runs of one style become a single range.
  • Editing follows the Mac's rule (MessageActions.canEdit), plus one check the Mac lacks: each mention must sit on its U+FFFC placeholder. The desktop app replies to, reacts to, edits, copies and deletes messages #180 had limited editing to plain text: messages with styles or mentions can now be edited, and ↑ edits the newest one. Starting an edit loads the message's styles and mentions back into the composer (mentions as tokens), and cancelling brings back what was typed before, styles included. Drafts keep only the words, as on the Mac.
  • Text put into the composer from outside (a draft, an edit, a failed send) now has the caret at its end, as the Mac's updateNSView does. Before, it was at the start.

The composer can't draw styles: what this does instead (a product question)

gpui-component's Textarea can't draw styled runs. Only its code editor (EditorState) takes text decorations. Those can't change the font (so no monospace), don't support inline tokens, and bring code-editor behaviour: a two-line minimum height, no auto-grow, indent handling and a monospace default. So the composer stays the Textarea and keeps each byte's styles beside its text. While any of the text is styled, a "Formatted" preview above the field shows it as it will go out (spoilers lightly shaded, as in the Mac's composer). Mentions do show in the field itself, as inline tokens.

Other options, if the preview isn't what you want:

  1. Use EditorState as the composer: bold, italic, strikethrough and spoiler shading inline, but monospace not shown and mentions as plain text plus a tracked range, with the quirks above to work around.
  2. Write our own text input element (about a thousand lines: IME, selection, undo, wrapping, scrolling).
  3. Ask upstream for decorations on Textarea.

Two smaller differences from the Mac:

  • A mention token is atomic: one Backspace deletes it whole, and the caret can't go inside it. On the Mac, typing into it turns it back into plain text.
  • Undo undoes typing, but not a style toggle. On the Mac, Undo also takes a style back.

Why

#139: the desktop app showed only bold mentions, sent no styles or mentions, and couldn't edit styled messages.

How it was tested

  • Unit tests (test-first; the new tests failed against stubs or the old rule before the code):
    • text::styled: overlapping styles and UTF-16 offsets, mentions taking the styles around them, spoilers covering mentions and running to the end of the text, revealing, hostile ranges and split emoji.
    • The composer model: typing and toggled styles, replacing and deleting, an input method's whole-text commit, toggling a style, the message's trimming, joined runs and mention placeholders, a full round trip of loading an edit and sending it, dropping ranges that don't fit, @word detection and member matching, preview runs.
    • Edit rules: styled and mention messages are editable, a two-unit mention is not, and ↑ picks the newest styled one.
  • cargo fmt --check; cargo clippy -p hush-desktop --all-targets -- -D warnings with and without --features snapshot; cargo test -p hush-desktop and cargo test -p hush-desktop --features snapshot (91 pass, including window tests of the picker, Esc, edits and toggled styles through the real field).
  • --snapshot screens, light and dark:
    • chat: every style in bubbles, a covered spoiler, a quote's mention.
    • New compose screen: a styled message with a mention token in the field, the preview, and the picker open.
    • reply and search-in-chat checked after merging main.
  • Not run: make check (it needs the signing certificate, which this Mac doesn't have). The live window and a linked phone weren't used, so the following are checked by unit tests and code reading only: the shortcuts, the Format menu (native menus don't render offscreen), the picker's keys, and real sending and editing.

No new dependencies, and no core changes.

Closes #139
Part of #157

Bubbles and quotes draw bold, italic, strikethrough, monospace and mentions; a spoiler stays covered until its message is clicked. The composer keeps each character's styles beside its text (gpui-component's textarea can't draw them) and previews the styled text above the field; Desktop's shortcuts and a Format menu style the selection or what's typed next. In a group, @ offers its members and a picked one is a mention token. Sending and editing carry the ranges, and messages with styles or mentions can be edited, loading them back into the composer.
…d-text

# Conflicts:
#	core/desktop/src/app/mod.rs
#	core/desktop/src/app/view.rs
#	core/desktop/src/main.rs
… mention list closed

The format shortcuts are bound as cmd or ctrl per system (KeyBinding::new can't read secondary-), and a test builds every binding the app registers. Esc on the mention list holds until no @word is typed, as on the Mac. Typing where no styles are known is plain instead of panicking; only an input method's whole-text commit is trimmed; an edit keeps a spoiler that runs past the end; a mention not on its placeholder isn't loaded, and its message isn't offered for editing. New unit and window tests cover picking a mention, edits going back with their ranges, styles toggled before typing and how runs join.
@pitis

pitis commented Nov 14, 2026

Copy link
Copy Markdown
Owner Author

Review findings and fixes (commit fa4317a)

Every new test was written first. Each test of a bug failed before its fix. Each test of code that was already correct failed against a deliberately broken copy (listed per item), then passed again once restored.

Critical

  1. The app panicked at launch. KeyBinding::new("secondary-b", …) can't parse secondary-. Fix: compose::keys() now uses cmd-… on macOS and ctrl-… elsewhere, as search::keys() does. main.rs's bindings moved into key_bindings(), which collects quit, search and compose. New test every_shortcut_parses builds them all: it panicked with InvalidKeystrokeError { keystroke: "secondary-b" } before the fix.

Important
2. Esc on the mention list lasted one keystroke. Fix: dismissed is cleared only when no "@word" is typed, as the Mac's MentionPicker.update does. Window test esc_closes_the_mention_picker_until_another_at_word (Esc → closed, "g" → still closed, " @" → open) failed before the fix.
3. typing() could index past the styles during input-method composition. Fix: every lookup uses get() and is plain when out of range. The other direct indexes were checked: edited only splices after verifying lengths, toggle uses get_mut, and message/runs use get. Test typing_where_no_styles_are_known_is_plain panicked before the fix.

Test gaps
4. Done. mentions_read_as_bold_names_in_a_bubble checks two mentions through styled(), both bold; it fails when the reverse sort is removed. marked() lost its unused position output and is folded into plain().
5. Done. only_touching_runs_of_one_style_go_out_as_one_range covers "a b c" → Bold(0,1), Bold(4,1), and bold "ab" + italic "cd" → Bold(0,2), Italic(2,2). It fails when the adjacency check is removed.
6. Done. Window test a_picked_member_goes_out_as_a_mention: ↓ wraps, ↩ picks, the text ends "@bogdan Ionescu ", and the message ends with U+FFFC under a Mention range at that unit. It fails without the wrap.
7. Done. Window test an_edited_message_goes_back_with_its_styles_and_mentions checks "On my way, 20 minutes" (Monospace 11..21), then one mention, then two mentions with bold around them, all through start_editing and set_typed. It fails when load ignores styles.
8. Done. a_toggle_keeps_the_other_styles (italic + spoiler, toggle bold on and off) fails with a toggle that overwrites. Window test styles_toggled_with_nothing_selected_go_to_what_is_typed_next (⌘B ⌘I then "x" → bold and italic; ⌘B ⌘B then "y" → plain) fails without the pending styles.
9. Done. Runs no longer join across a gap in runs() or styled() (tests fail when the adjacency check is removed). mention_query("@an x", &[], 3) → Some((0..3, "an")) (fails with the caret ignored).
10. Fixed. load takes a mention only when it sits on U+FFFC. can_edit requires the same, so such a message isn't offered for editing instead of losing the mention on save. This is stricter than the Mac's canEdit. Tests a_mention_not_on_a_placeholder_isnt_loaded (gave "@name a\u{FFFD}" before the fix) and a can_edit case for "👍 hi" with mention(0) both failed before the fix.
11. Done. an_edit_leaves_out_ranges_that_dont_fit now asserts on message(&typed).1. The round trip compares ranges as sets, which avoids the Spoiler/Mention tie at (3,1). typed_into is gone.

Suggestions
12. Fixed. Only an input method's whole-text commit (0..old.len()) is trimmed; other edits use their exact ranges, with a shortcut: comment for "か before か". Test typing_over_a_selection_takes_its_first_characters_styles_even_if_the_same_letter_follows gave [0, 0] instead of [BOLD, 0] before the fix.
13. Done. load clamps a spoiler that runs past the end, so saving an edit unchanged keeps it covered. Test an_edit_keeps_a_spoiler_running_past_the_end_covering_to_the_end failed before the fix.

Ruling applied: the "Formatted" preview stays. Atomic mention tokens and Undo not taking back a style toggle are now shortcut: comments in compose.rs (pick_mention, toggle_style), and the PR body lists them.

Checks:

  • cargo fmt --check: clean.
  • cargo clippy -p hush-desktop --all-targets -- -D warnings, with and without --features snapshot: clean.
  • cargo test -p hush-desktop: 83 pass; with --features snapshot: 91 pass.
  • make update: up to date with main.
  • Snapshots re-rendered: unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The desktop app shows formatted text and writes it, with mentions

1 participant