Skip to content

fix(ui): preserve composer paste undo history - #3787

Open
Sun-GLiang wants to merge 3 commits into
apache:mainfrom
Sun-GLiang:fix/3786-composer-paste-undo
Open

fix(ui): preserve composer paste undo history#3787
Sun-GLiang wants to merge 3 commits into
apache:mainfrom
Sun-GLiang:fix/3786-composer-paste-undo

Conversation

@Sun-GLiang

@Sun-GLiang Sun-GLiang commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • route ordinary inline plain-text paste through the existing ChatComposerInput.onPaste seam
  • use an escaped insertHTML browser transaction so paste is undone separately from immediately preceding keyboard input
  • preserve the existing file, reference-sized token, token-adjacent, attachment, and IME paste paths
  • add an Electron regression test covering repeated undo and plain-text fidelity for Chinese, URLs, multiline text, and HTML-special characters

Fixes #3786

Before / after evidence

Both corrected recordings run the same real Electron flow with the same minimal input: type x → paste ordinary multiline text → press undo three times. Each step displays the current composer text.

Before — upstream/main@7235069ad

The first undo removes x while leaving the pasted text. The second and third undo still leave the pasted text, reproducing #3786.

page@c2ccde11c524db300d1090fd7f645c92.webm

After — f547283a8

The first undo removes only the pasted text and leaves x; the second removes x; the third remains empty without reinsertion or duplication.

page@7da85ab9fe494f70134e34b1ff7e7118.webm

Verification

Passed locally:

  • npm --workspace @maka/desktop run e2e -- composer-undo.spec.ts
  • npm run lint
  • npm run format:check
  • npm run typecheck
  • npm run check:asf-headers
  • npx knip --workspace packages/ui
  • npx knip --workspace apps/desktop
  • npm run build

The full local npm test command reached two unrelated failures in unchanged workspaces:

  • @maka/runtime: an environment-sensitive assertion expects /usr/local at executable-root index 1 even though the current Node executable already makes it the deduplicated index 0 root.
  • @maka/runtime-host: cleanup of the shared ~/Library/Caches/Maka/runtime-hosts directory raced with a locally running Host and failed with ENOTEMPTY.

Current CI status

The PR CI build is currently blocked by the same regression already failing on its base commit main@689a4515f:

Both fail while building unchanged packages/runtime-host/src/__tests__/execution-host-queue.test.ts, where RuntimeHostConnection no longer exposes queryTurn, stopTurn, or startTurn. Neither packages/runtime-host nor packages/runtime differs from main in this PR. Re-running the PR workflow before main is repaired will reproduce the same failure.

AI use

Select exactly one:

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Tool(s) and scope: Codex implemented the focused composer change, added the Electron regression test, ran verification, and performed code review. The commit includes the required Generated-by trailer.

Checklist

  • Tests cover the change and fail without it
  • Lint, format, typecheck and the affected suites pass locally

Does this PR entail a change in behavior?

  • Yes — described under Summary above
  • No

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I reviewed this head and found no blocking issues.

The paste now uses execCommand('insertHTML') on a textContent-escaped <br> conversion to make plain-text paste a separate undo transaction, correctly leaving file/reference/IME paths unchanged.

Minor note: execCommand is deprecated but the only remaining transactional insertion primitive in this composer — consider annotating a future migration path.

No P0-P2. Checks on 7afde75d95 are blocked by base execution-host-queue failure unrelated to this change.

简体中文该头未发现阻断,execCommand 废弃为轻度可维护性观察。

@M4n5ter
M4n5ter force-pushed the fix/3786-composer-paste-undo branch 2 times, most recently from 7a130ef to f28a37f Compare August 26, 2026 09:48
@M4n5ter
M4n5ter force-pushed the fix/3786-composer-paste-undo branch from f28a37f to 50ab1d7 Compare August 26, 2026 09:55
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.

bug(desktop): composer undo skips and may duplicate pasted content

2 participants