feat(web): add surround selection in composer#1502
feat(web): add surround selection in composer#1502juliusmarminge merged 26 commits intopingdotgg:mainfrom
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
… feature/surround-selection
ApprovabilityVerdict: Needs human review This PR introduces a new user-facing feature: surround selection behavior in the composer that wraps selected text with matching bracket/quote pairs. The change adds ~260 lines of new plugin code with complex event handling (keyboard, input, composition events) and edge case logic for mentions. New features introducing new UI behavior warrant human review regardless of scope. You can customize Macroscope's approvability policy. Learn more. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 25be906. Configure here.
- Keep dead-key surround selection reversible with a single undo - Add regression coverage for composed surround input

What
Add surround-selection support in the composer so that when text is selected and the user types a supported surround symbol, the selection is wrapped instead of replaced.
This also includes dead-key backtick support, so layouts that produce
`through composition can still surround the selected text.Currently applies to these symbols:
(,[,{,',",`,<,«,*,_Why
I understand this is a feature and not a bug fix, and might land outside of what you are likely to accept re: the contribution guidelines. But it's something I always miss in editors when they don't have it, since I habitually select text and press parenthesis, quote or whatever.
If this is something that should be opt-in behind a setting, I can add that as well.
Checklist
Video
t3code-surround-selection.mov
Note
Medium Risk
Intercepts
keydown/beforeinput/composition events in the Lexical composer to rewrite prompt text and selection, which can regress typing/IME behavior around mentions and inline tokens despite added tests.Overview
Composer typing enhancement: when text is selected in the chat composer and the user types a supported opening symbol (e.g.
(,",`,*), the selection is wrapped with the matching close symbol and the inner selection is preserved for repeated wrapping.Adds a new
ComposerSurroundSelectionPluginthat hookskeydown/beforeinput/input/compositionend, skips wrapping when the selection is collapsed, touches inline tokens, or crosses mention-boundary whitespace, and merges dead-key backtick composition into a single undo step.Extends mention parsing utilities with
selectionTouchesMentionBoundaryand fixessplitPromptIntoComposerSegmentsto preserve consecutive terminal-context placeholders; adds browser/integration tests covering wrapping, backward selections, dead-key composition, and mention edge cases.Reviewed by Cursor Bugbot for commit 8daa878. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Add surround selection to the composer for wrapping selected text with paired symbols
ComposerSurroundSelectionPluginin ComposerPromptEditor.tsx that interceptsbeforeinput/keydownevents: when a recognized open symbol (e.g.(,[,',*,«) is typed with a non-collapsed selection, the plugin wraps the selected text with the corresponding pair and keeps the inner text selected for successive wrapping.selectionTouchesMentionBoundaryin composer-editor-mentions.ts to detect when a selection includes mention-adjacent whitespace.HISTORY_MERGE_TAG.splitPromptIntoComposerSegmentsto preserve consecutive terminal-context placeholders as distinct segments.Macroscope summarized 8daa878.