Repository navigation
Fix surrounding a selection with brackets after arrow functions (#225916) - #321210
Dmitriy Vasyura (dmitrivMS) merged 4 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR fixes an auto-indent edge case when typing a bracket/brace while a selection exists (e.g., “surround selection”) after an arrow function, and adds a regression test for the reported issue.
Changes:
- Add a regression test covering “surround selection with
{}after an arrow function” (issue #225916). - Adjust auto-indent logic to only consult previous-line “indent next line” rules when the typed range is empty (caret insertion, not replacement).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/vs/editor/contrib/indentation/test/browser/indentation.test.ts | Adds a regression test reproducing the surround-selection behavior after an arrow function. |
| src/vs/editor/common/languages/autoIndent.ts | Prevents previous-line indent-next-line inheritance when typing replaces a selection. |
|
@microsoft-github-policy-service agree |
|
question: Since the issue description mentions |
|
Roqia AlQoran (@royy92)
Copilot pointed at the same test, too. |
|
Closing since I am unable to repro the issue this is fixing. |
|
I independently validated this fix on Windows against PR head BaselineI applied only the new regression test to current PR head
I also applied the two-file PR diff onto current Code OSS verificationBuilt and launched Code OSS from the PR head with a TypeScript file using
The |
…osoft#225916) (microsoft#321210) * fix: only auto indent on type when the selection is empty * test: surround a selection with brackets after arrow functions * test: surround a selection with all bracket pairs after arrow functions --------- Co-authored-by: Dmitriy Vasyura <[email protected]> (cherry picked from commit 45a37d5)

issue
resolve #225916
background
Since VS Code 1.91, typing
{,[or(over a selected text deletes the selection instead of surrounding it, when the line above ends with=>(or is anif/for/whilewithout braces) in TypeScript/JavaScript.Expected:
{doSomething()}Actual: the selection is deleted and
{is inserted at the start of the line.This happens with the default settings (
editor.autoIndent: "full").problem
nand increaseNextLinePattern is satisfied on linen-1#216500), which added a new branch togetIndentActionForTypeto support allman-style braces (Wrong auto-indentation in typescript #209802).textAroundRange, which contains only the text around the range — the selected text is excluded. A selection covering the rest of the line therefore passes the check.vscode/src/vs/editor/common/languages/autoIndent.ts
Lines 421 to 427 in 43a13ca
AutoIndentOperationruns beforeSurroundSelectionOperationin the typing pipeline, so once the branch fires, surround-with-brackets is never reached.vscode/src/vs/editor/common/cursor/cursorTypeOperations.ts
Lines 172 to 190 in 43a13ca
vscode/src/vs/editor/common/cursor/cursorTypeEditOperations.ts
Lines 96 to 107 in 43a13ca
fix
range.isEmpty()).SurroundSelectionOperation, restoring the pre-1.91 behavior.checks
Verified manually with a build from source
Followed the repro steps from the issue: the selection is now surrounded (
{doSomething()}), and[/(work as well.Added a regression test, and confirmed it fails without the fix (reproducing the exact behavior reported in the issue)
./scripts/test.sh(full unit tests), hygiene, eslint andvalid-layers-checkall pass