Skip to content

fix(web-ui): fix composer undo, sent large pastes, and bubble collapse - #3745

Merged
bobleer merged 4 commits into
openBitFun:mainfrom
bobleer:bob/composer-undo-large-paste-viewer
Nov 5, 2026
Merged

bobleer merged 4 commits into
openBitFun:mainfrom
bobleer:bob/composer-undo-large-paste-viewer

Conversation

@bobleer

@bobleer bobleer commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes three chat composer / sent-message issues in the Web UI:

  1. Large pastes are unreadable after sending. The composer collapses long pastes into [Pasted content N chars]; the model always received the full text, but the sent bubble only kept the placeholder, and copy copied the placeholder. Paste bodies are now stored in user message metadata (largePastes). The placeholder renders as a borderless capsule that opens a read-only viewer with copy, and message copy, edit, rollback, and fill-to-input all use the real text (restored composer drafts get their paste capsules back).
  2. An expanded user message collapses on any outside click, so moving to the copy button (outside the bubble) collapsed it before the click landed. The outside-mousedown collapse is removed; only a click inside the bubble collapses it.
  3. One Cmd+Z undoes too much. WKWebView coalesces a typing run, including IME commits, into one native undo step, so 12345 + IME 你好 + Cmd+Z cleared everything. The composer now owns its undo history: steps break at words, 1s pauses, IME commits, insert/delete changes, and programmatic capsule inserts. Cmd/Ctrl+Z, Cmd+Shift+Z, Ctrl+Y, and Edit-menu historyUndo/historyRedo are handled; capsules, contexts, and large pastes are restored. The existing image-paste undo still takes precedence.

Also fixes a latent expansion bug: two pastes of the same length produce [... N] and [... N] #2, and expanding in insertion order corrupted the #2 paste. Expansion is now longest-match-first.

Type and Areas

Type: bug fix, UI/UX

Areas: web UI

Motivation / Impact

  • Users can read, copy, and re-edit long pasted content after sending.
  • Copy/edit actions on long expanded messages are clickable.
  • Undo after IME input removes only the last step instead of the whole draft.

Verification

  • pnpm --dir src/web-ui run type-check: pass
  • pnpm --dir src/web-ui run test:run src/flow_chat/components src/flow_chat/hooks src/flow_chat/utils: 252 files / 2625 tests pass. New tests:
    • richTextInputHistory.test.ts: grouping rules, including the IME commit case
    • RichTextInput.test.tsx: typing + IME commit, then undo/redo through the real editor; large paste capsule restore
    • UserMessageItem.test.tsx: stays expanded on outside mousedown; paste capsule opens viewer; copy expands paste
    • largePasteMetadata.test.ts: same-length placeholders, no body rescan, tolerant metadata parsing
    • useMessageSender.test.tsx: largePastes metadata is sent
  • eslint on changed source files: clean
  • pnpm run theme:color-audit:all: pass. The MiniApp chat style projection was regenerated (only the new viewer rule).
  • Follow-up: pnpm run check:web (type-check + Appearance/theme gates): pass.
  • Follow-up: 150 focused input/message tests pass; 52 message presentation/preview/action tests pass (overlapping coverage).
  • Follow-up: eslint on changed production source and git diff --check: pass.
  • Not yet exercised manually in the desktop app. Remote coverage is limited to local session/device identity fixtures; no live SSH, Remote Control, Peer Device or Detached Dispatch validation.

Review follow-up

  • Preserve freshly inserted context capsules and large-paste bodies before React commits parent state, so undo/redo restores executable references and full content. Same-length paste-body edits now form undo steps too.
  • Restore the exact paste placeholder map during history navigation, and match overlapping placeholders longest-first when pruning/storing metadata; deleted shorter-prefix pastes are not retained.
  • Reset composer undo/redo on session/device activation changes even when both drafts have identical text. Start a new undo step after caret movement or selection replacement.
  • Remove an unused, unregistered Appearance state attribute discovered by the full check:web gate; no audit baselines were loosened.
  • Added controlled-editor regression fixtures for repeated undo/redo, paste body edits, newly inserted contexts, session/device scope changes, and caret movement. Review and follow-up changes are AI-assisted.

Reviewer Notes

  • Compatibility: the paste bodies live in a separate largePastes metadata key, not a new composerPresentation segment kind, because the Rust turn-rail parser drops presentations with unknown segment kinds. Older builds, mobile web, and IM bots ignore the key and keep showing the placeholder as before. Malformed metadata is ignored.
  • Remote scenarios: frontend-only. The model prompt is unchanged (still inline full text), and metadata is opaque JSON to the backend, so remote workspace, Peer Device, and Detached Dispatch behavior is unchanged. Only tested locally (jsdom).
  • Undo snapshots serialize through the existing composer presentation rather than cloning DOM, because capsules bind onclick handlers that clones would lose. External value syncs (send, history navigation, draft restore) reset the history baseline.

Checklist

  • This PR is focused and does not include secrets, temporary prompts, generated scratch files, or unrelated artifacts.
  • Relevant verification is recorded above, or skipped checks are explained.
  • User-facing strings, docs, and locales are updated where applicable. (Reuses existing input.largePaste* keys; no new strings.)

- Own the composer undo history: WebKit coalesces a typing run, including
  IME commits, into one native undo step, so a single Cmd+Z cleared the
  whole draft. Steps now break at words, pauses, IME commits, edit-kind
  changes, and programmatic capsule inserts; capsules, contexts, and large
  pastes are restored on undo/redo.
- Keep large paste bodies in user message metadata (`largePastes`) so the
  sent placeholder opens a read-only viewer, and copy, edit, rollback, and
  fill-to-input use the real text. Older builds ignore the key.
- Expand same-length paste placeholders longest-first so `[... N] #2`
  is no longer corrupted by the `[... N]` prefix.
- Stop collapsing an expanded user message on outside mousedown, which
  moved the copy/edit actions before the click landed.
@bobleer
bobleer merged commit d4f2780 into openBitFun:main Nov 5, 2026
12 checks passed
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.

1 participant