fix(session-ui): preserve caret after prompt editor rebuild - #42297
Open
gold-beyond wants to merge 1 commit into
Open
fix(session-ui): preserve caret after prompt editor rebuild#42297gold-beyond wants to merge 1 commit into
gold-beyond wants to merge 1 commit into
Conversation
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
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
Fixes #42335
Related to #37037 / #36210 (caret jumps around in the prompt input while the
session updates). This PR fixes the variant I could reproduce and verify on the
current v2 composer: inserting a @mention mid-text on the session page
collapses the caret to the END of the prompt instead of keeping it right after
the mention. I could not reproduce the streaming-output case from #37037 on
current
dev, so I only claim the mention-insertion scenario here.Type of change
What does this PR do?
renderPromptInputV2Editorrebuilds the editor DOM (replaceChildren) wheneverthe prompt store changes outside a local input (mention insertion, history
navigation, followup edit). After the rebuild it always collapsed the caret to
the end of the editor, ignoring the cursor position stored in the prompt store.
Reproduced on the session page: after inserting
@src/index.tsmid-text, thecaret lands at offset 32 (end of a 32-char prompt) instead of 21 (right after
the mention).
Changes in
packages/session-ui/src/v2/components/prompt-input:interaction.ts: exposecursor()on the controller so the editor can readthe authoritative stored caret position.
index.tsx: restore the caret from the stored cursor after a rebuild, fallingback to the pre-rebuild DOM caret when no cursor is stored. Mentions are
uneditable spans that still occupy their text length, so
setPromptInputV2Cursorplaces the caret before/after a mention, never insideit.
How did you verify your code works?
packages/app/e2e/regression/prompt-caret-after-mention.spec.ts:types "please fix the bug", moves the caret to offset 7, inserts
@src/index.tsmid-text on a session page, and asserts the caret lands atoffset 21. It failed before the fix (caret at 32) and passes after.
Run with:
bunx playwright test e2e/regression/prompt-caret-after-mention.spec.tsbun run typecheckinpackages/session-uipasses.bun test srcinpackages/session-ui: 83 tests pass.prompt-input-v2-command-draft) still passes.Checklist