Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix HTML formatting when using tabs #3556

Merged
merged 4 commits into from May 7, 2021

Conversation

davidwengier
Copy link
Contributor

Fixes AB#1273468

(and in case that doesn't work, Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1273468/)

When reformatting we used to look at the existing formatting and base changes on that. When formatting things with tabs, that fell down because we'd see \t\t and think "oh, they want two spaces of indentation". This PR adds a new field so that we can think "oh, they want 8 columns of indentation" instead.

@davidwengier davidwengier marked this pull request as ready for review May 6, 2021 02:58
@davidwengier davidwengier changed the title Add failing tests Fix HTML formatting when using tabs May 6, 2021
}

[Fact]
[WorkItem("https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1273468/")]
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah should I have linked this issue to my one-off PR I did to WebTools?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you turning away from your life of crime?

@@ -336,7 +336,9 @@ protected async Task<List<TextChange>> AdjustIndentationAsync(FormattingContext
{
// Given that the HTML formatter ran before this, we can assume
// HTML is already correctly formatted. So we can use the existing indentation as is.
razorDesiredIndentation = context.Indentations[i].ExistingIndentation;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we still use ExistingIndentation anywhere / is it still valuable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, still used for sure.

Lets say after the HTML formatter runs, we get back this:

→→∙∙<br />

So thats two tabs, and two spaces, so an indentation of 4, but an indentation size of 10. Well, we run the indentation pass, we now correctly use ExistingIndentationSize to get back an answer of 10 to create our indentation string, but we still need ExistingIndentation to know how many characters to replace when we perform the edit.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahhh awesome explanation, thank you!

@davidwengier davidwengier merged commit 2a010d0 into dotnet:main May 7, 2021
@davidwengier davidwengier deleted the FixHtmlTabFormatting branch May 7, 2021 03:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants