Browse files

Fix two issues:

First, make sure the command doesn't show up in tool windows where you couldn't possibly use it, and set the default visibility and state to invisible/disabled.

Second, fix cases where the = is directly preceeded by non-punctuation text, which was incorrectly getting aligned with the = sign.
  • Loading branch information...
1 parent 3392b77 commit 88e6f2d437751b0280f6d4efd727f2a28a6c9dc7 Noah Richards committed Apr 5, 2010
Showing with 13 additions and 3 deletions.
  1. +2 −0 AlignAssignments.vsct
  2. +11 −3 CommandFilter.cs
View
2 AlignAssignments.vsct
@@ -17,6 +17,8 @@
<Icon guid="guidImages" id="bmpPic1" />
<CommandFlag>DynamicVisibility</CommandFlag>
<CommandFlag>DontCache</CommandFlag>
+ <CommandFlag>DefaultDisabled</CommandFlag>
+ <CommandFlag>DefaultInvisible</CommandFlag>
<Strings>
<CommandName>cmdidAlignAssignments</CommandName>
<ButtonText>Align Assignments</ButtonText>
View
14 CommandFilter.cs
@@ -17,7 +17,7 @@ namespace NoahRichards.AlignAssignments
{
[Export(typeof(IVsTextViewCreationListener))]
[ContentType("code")]
- [TextViewRole(PredefinedTextViewRoles.Interactive)]
+ [TextViewRole(PredefinedTextViewRoles.Editable)]
class VsTextViewCreationListener : IVsTextViewCreationListener
{
[Import]
@@ -167,8 +167,9 @@ private ColumnAndOffset GetColumnNumberOfFirstEquals(ITextSnapshotLine line)
if (ch == '=')
return new ColumnAndOffset() { Column = column,
Offset = (i - line.Start.Position) - nonWhiteSpaceCount };
-
- if (ch == '\t' || ch == ' ')
+
+ // For the sake of associating characters with the '=', include only
+ if (!CharAssociatesWithEquals(ch))
nonWhiteSpaceCount = 0;
else
nonWhiteSpaceCount++;
@@ -198,6 +199,13 @@ struct ColumnAndOffset
public int Offset;
}
+ static HashSet<char> charsThatAssociateWithEquals = new HashSet<char>()
+ { '+', '-', '.', '<', '>', '/', ':', '\\', '*', '&', '^', '%', '$', '#', '@', '!', '~' };
+ private bool CharAssociatesWithEquals(char ch)
+ {
+ return charsThatAssociateWithEquals.Contains(ch);
+ }
+
private bool AssignmentsToAlign
{
get

0 comments on commit 88e6f2d

Please sign in to comment.