fix(app): preserve undo history when inserting tag pills in prompt input#22237
Open
callmeYe wants to merge 1 commit intoanomalyco:devfrom
Open
fix(app): preserve undo history when inserting tag pills in prompt input#22237callmeYe wants to merge 1 commit intoanomalyco:devfrom
callmeYe wants to merge 1 commit intoanomalyco:devfrom
Conversation
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
…tory
When inserting file/agent tag pills into the contenteditable prompt input,
direct DOM manipulation (range.insertNode) bypasses the browser's native
undo stack. Pressing Ctrl+Z after inserting a tag deletes the text before
the tag instead of removing the tag itself.
Switch to document.execCommand("insertHTML") which registers the operation
on the undo stack. Falls back to the previous range.insertNode approach
when execCommand is unavailable.
Closes anomalyco#22234
a554c4b to
a139127
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #22234
Type of change
What does this PR do?
When inserting file/agent tag pills into the
contenteditableprompt editor, the current code usesrange.insertNode()— a direct DOM operation that bypasses the browser's native undo stack. This means pressing Ctrl+Z after inserting a tag doesn't undo the tag insertion; instead it undoes whatever happened before the tag (typically deleting preceding text).This PR introduces a small helper (
editor-insert.ts) that usesdocument.execCommand("insertHTML")to insert the pill HTML. AlthoughexecCommandis deprecated, it remains the only reliable way to push operations onto the browser's built-in undo/redo stack in acontenteditableelement. The call site inprompt-input.tsxtriesinsertAtomicPartAtSelection()first, and falls back to the originalrange.insertNodepath ifexecCommandis unavailable.Files changed:
packages/app/src/components/prompt-input/editor-insert.ts(new) —serializeAtomicPartHtml()+insertAtomicPartAtSelection()helperpackages/app/src/components/prompt-input/editor-insert.test.ts(new) — unit tests for HTML serialization, XSS escaping, and execCommand usagepackages/app/src/components/prompt-input.tsx— import the helper, replace the direct DOM insertion with the execCommand approach + fallbackHow did you verify your code works?
bun test editor-insert.test.ts— 5 tests, 13 assertions)@→ Ctrl+Z correctly removes the tag pill (not the preceding text)Screenshots / recordings
N/A — this is an interaction behavior fix, best verified by testing Ctrl+Z after inserting a tag pill.
Checklist