Skip to content

feat(web): add surround selection in composer#1502

Merged
juliusmarminge merged 26 commits intopingdotgg:mainfrom
mbuvarp:feature/surround-selection
Apr 10, 2026
Merged

feat(web): add surround selection in composer#1502
juliusmarminge merged 26 commits intopingdotgg:mainfrom
mbuvarp:feature/surround-selection

Conversation

@mbuvarp
Copy link
Copy Markdown
Contributor

@mbuvarp mbuvarp commented Mar 28, 2026

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

  • This PR is small and focused
  • I explained what changed and why
  • I included a video for animation/interaction changes

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 ComposerSurroundSelectionPlugin that hooks keydown/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 selectionTouchesMentionBoundary and fixes splitPromptIntoComposerSegments to 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

  • Adds ComposerSurroundSelectionPlugin in ComposerPromptEditor.tsx that intercepts beforeinput/keydown events: 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.
  • Selections that touch mention boundary whitespace or inline tokens fall back to normal replacement behavior.
  • Adds selectionTouchesMentionBoundary in composer-editor-mentions.ts to detect when a selection includes mention-adjacent whitespace.
  • Dead-key backtick composition is detected and transformed into a backtick surround in a single undo step via HISTORY_MERGE_TAG.
  • Fixes splitPromptIntoComposerSegments to preserve consecutive terminal-context placeholders as distinct segments.

Macroscope summarized 8daa878.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 28, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 58b98e5a-cf94-4832-8b51-9a22818a6b0a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added size:L 100-499 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list. labels Mar 28, 2026
@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp bot commented Apr 9, 2026

Approvability

Verdict: 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.

Copy link
Copy Markdown
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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.

@juliusmarminge juliusmarminge enabled auto-merge (squash) April 10, 2026 00:51
@juliusmarminge juliusmarminge merged commit 65d797c into pingdotgg:main Apr 10, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants