Skip to content

Conversation

@JoeRobich
Copy link
Member

@JoeRobich JoeRobich commented Jan 23, 2025

Enables format on type when the trigger character is a newline. Removes text changes that contain the cursor as we do not want to remove the indentation.

FormatOnType.NewLine.mp4

Resolves dotnet/vscode-csharp#6834

@JoeRobich JoeRobich requested a review from dibarbet January 23, 2025 00:41
@JoeRobich JoeRobich requested a review from a team as a code owner January 23, 2025 00:41
@ghost ghost added Area-Infrastructure untriaged Issues and PRs which have not yet been triaged by a lead labels Jan 23, 2025
{
// When formatting after a newline is pressed, the cursor line will be blank and we do
// not want to remove the whitespace indentation from it.
textChanges = textChanges.WhereAsArray(change => !change.Span.Contains(position));
Copy link
Member

Choose a reason for hiding this comment

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

i'm not really getting the comment. in the case of a newline, you do remove some of the changes. could you bemore specific in the comment, perhaps with examples of the data we get back, what we want to filter out, and waht we want to keep?

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated!

// Letting the second change go through would be a bad experience for the user as they
// will now be responsible for adding back the proper indentation.

textChanges = textChanges.WhereAsArray(static (change, position) => !change.Span.Contains(position), position);
Copy link
Member

Choose a reason for hiding this comment

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

great comment. very helpful. would it make sense to also add a condition that that final span of the change is empty? basically, it would b only filtering out the formatting change that deletes the code the caret it at.

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks like I was imprecise and will update the comment.

The second change runs from the start of the cursor line to the closing brace. It removes the whitespace from the cursor line and rewrites the indentation on the line with the closing brace. The 14 characters \r\n is replaced with \r\n .

Copy link
Contributor

@ToddGrun ToddGrun left a comment

Choose a reason for hiding this comment

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

:shipit:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Infrastructure untriaged Issues and PRs which have not yet been triaged by a lead VSCode

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Automatically move { opening braces down to a new line when pressing enter

5 participants