XamlStyler icon indicating copy to clipboard operation
XamlStyler copied to clipboard

Keep comment on same line

Open CodeAnthem opened this issue 3 years ago • 11 comments

Hello, I'd like to have my comments for ColumnDefinition and RowDefinition on same line, is there any option to do that? Or could one be implemented?

Thanks :)

CodeAnthem avatar Feb 19 '21 14:02 CodeAnthem

Can you show a before and after example of what you are looking to achieve here?

grochocki avatar Feb 22 '21 03:02 grochocki

Before: (this is what I try to archieve) <RowDefinition Height="50" /> <!-- Title --> <RowDefinition Height="*" /> <!-- Main Content -->

After:

<RowDefinition Height="50" />
<!-- Title  -->
<RowDefinition Height="*" />
<!-- Main Content  -->

Thanks alot

CodeAnthem avatar Feb 22 '21 14:02 CodeAnthem

I agree, but I'd like to extend this request, so that an option is provided to have any comment left in situ, not just after Row and ColumnDefinitions. Very often I want a comment to be after a XAML declaration but on the same line so it more obviously explains the purpose of the XAML.

Here's an example of what I want, before applying "Format XAML":

<Brush x:Key="Theme.Background">#FF5D6B99</Brush> <!-- This is the Main Background color for the Theme -->

. . . . . . and this is what I now get after applying "Format XAML":

<Brush x:Key="Theme.Background">#FF5D6B99</Brush>  
<!--  This is the Main Background color for the Theme  -->

Because I use comments on the same line quite extensively, my XAML can get quite ugly and unreadable after formatting with XAML Styler.

I think this could be achieved relatively easily, by specifying an optional first character in the XAML comment that doesn't typically appear as the first character of a string comment (eg another "<") . The presence of that first character indicates the comment should be exempt from normal styling (in other words left wherever it was put); absence of that special first character means the comment is subject to normal styling rules and placed on the next line, as is the current default. Hence the following line would result in no change after applying "Format XAML":

<Brush x:Key="Theme.Background">#FF5D6B99</Brush> <!-- <This is the Main Background color for the Theme -->

sojatay avatar Mar 08 '21 19:03 sojatay

I would also like to keep comments on the same line. Mostly for Row/Column definition comments though. So it would be great with an option for those at least.

atlemann avatar May 11 '21 09:05 atlemann

I understand the use case better now, and I agree with @sojatay that this would be better implemented as a broader setting around preserving comment location, though I am not a fan of adding non-standard/special characters:

I think this could be achieved relatively easily, by specifying an optional first character in the XAML comment that doesn't typically appear as the first character of a string comment (eg another "<") . The presence of that first character indicates the comment should be exempt from normal styling (in other words left wherever it was put); absence of that special first character means the comment is subject to normal styling rules and placed on the next line, as is the current default.

Maybe it can be done without the special character by keeping track of whether the comment originates on its own line?

grochocki avatar May 17 '21 03:05 grochocki

Yes, that would be better than having to use some special character. Thanks for a great tool btw.

atlemann avatar May 18 '21 06:05 atlemann

@grochocki . What you have suggested is much better than the unnecessarily complicated "solution" I proposed.

Maybe you could check if the comment start tag is preceded only by white space on the line it appears in - in which case it should be subject to formatting by XAML Styler. If there are characters other than white space on the comment's line, it should stay on that line.

...or maybe even......just give an option to "Exclude Comments from Styler Formatting" ?? It's slightly cruder, but would enable comments to be left wherever the developer wrote them.

Overall the tool is fantastic for me - and this small limitation is the only minor niggle I have with it. Thank you for it.

sojatay avatar May 18 '21 14:05 sojatay

I really like this extension, your doing a great job at it. Having the comments automatically placed on a new line is bugging me. If there could just be a "keep comments on same line" option would be great.

So that before apply XAML styler:

<ColumnDefinition Width="50" /><!--Name Column-->
<ColumnDefinition Width="70" /><!--Date Column-->

This is what after XAML styler currently does (unwanted):

<ColumnDefinition Width="50" />
<!--  Name Column  -->
<ColumnDefinition Width="70" />
<!--  Date Column  -->

and this is what I prefer, after apply XAML styler:

<ColumnDefinition Width="50" /><!--Name Column-->
<ColumnDefinition Width="70" /><!--Date Column-->

HKLM avatar Jul 13 '22 02:07 HKLM

Has there been any progress on this? This feature request is 18 months old now. It seems to be a popular enhancement, and the position of trailing comments after applying XAML styler still bugs me a lot.

I'd do it myself in a fork if I believed I was competent to do so. I'm not!

sojatay avatar Aug 07 '22 23:08 sojatay

I just discovered this tool and I think it's great! But I would also like this feature. In my case, most of my inline comments are after RowDefinition and ColumnDefinition. Personally, I also like to line up those comments vertically (with some padding):

<RowDefinition Height="Auto">    <!-- Title -->
<RowDefinition Height="*">       <!-- Content -->

redcurry avatar Nov 09 '22 15:11 redcurry