microsoft / microsoft/vscode

Comment toggle corrupts CSS containing commented blocks

Open
#330,214 0 comments 0 reactions 1 assignee Claimed by @aiday-mar View on GitHub
bug editor-comments
Dominant language
TypeScript
Stars
193k
Forks
42.4k
PR merge metrics
PR metrics pending

Description

Does this issue occur when all extensions are disabled?: Yes/No

VS Code Version: 1.132.0
OS Version: Sonoma 14.0 (23A344)

Steps to Reproduce:

1. Open a .css file and paste the following code:

```css
.select {}

/*.select {*/
/* color: red; */
/*}*/
```

```css
.select {
color: red;
}

/*.select {
color: red;
}*/
```

2. Select all lines (or select the block).
3. Press `CMD+/` (toggle line comment).

Actual result:

```css
/* .select {
color: red;
}

/*.select {
color: red;
}*/ */ <------ syntax error
```

```css
.select {}

/*.select {*/
/* color: red; */
} <------ syntax error
```

Expected result:

VS Code should toggle comments cleanly (e.g., properly wrap each line or block without breaking syntax), and preserve existing comments and only toggle uncommented lines:

```css
/*.select {}*/

/*!*.select {*!*/
/*!* color: red; *!*/
/*!*}*!*/
```

```css
/*.select {*/
/* color: red;*/
/*}*/

/*!*.select {*/
/* color: red;*/
/*}*!*/
```

https://github.com/user-attachments/assets/343a0c85-e3cc-4c3f-8bb8-f3a7b2733ea3

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.