Problem with Fast Colored Textbox (indentation)

Asked

Viewed 266 times

9

I’m modifying an open source project created by Pavel Torgashov, called Fast Colored Textbox, and I’m having problems with the language VB in the editor, because methods and properties are indented within Interfaces...

Instead of her being like this:

Invés de ficar assim

It’s like this:

erro

And the rest of the code inside that FCTB is indented forward. Here is the original VB paragraph code (In C#) (Extracted from the class SyntaxHighlighter):

    protected void VBAutoIndentNeeded(object sender, AutoIndentEventArgs args)
    {
        //end of block
        if (Regex.IsMatch(args.LineText, @"^\s*(End|EndIf|Next|Loop)\b", RegexOptions.IgnoreCase))
        {
            args.Shift = -args.TabLength;
            args.ShiftNextLines = -args.TabLength;
            return;
        }
        //start of declaration
        if (Regex.IsMatch(args.LineText,
                          @"\b(Class|Property|Enum|Structure|Sub|Function|Namespace|Interface|Get)\b|(Set\s*\()",
                          RegexOptions.IgnoreCase))
        {
            args.ShiftNextLines = args.TabLength;
            return;
        }
        // then ...
        if (Regex.IsMatch(args.LineText, @"\b(Then)\s*\S+", RegexOptions.IgnoreCase))
            return;
        //start of operator block
        if (Regex.IsMatch(args.LineText, @"^\s*(If|While|For|Do|Try|With|Using|Select)\b", RegexOptions.IgnoreCase))
        {
            args.ShiftNextLines = args.TabLength;
            return;
        }

        //Statements else, elseif, case etc
        if (Regex.IsMatch(args.LineText, @"^\s*(Else|ElseIf|Case|Catch|Finally)\b", RegexOptions.IgnoreCase))
        {
            args.Shift = -args.TabLength;
            return;
        }

        //Char _
        if (args.PrevLineText.TrimEnd().EndsWith("_"))
        {
            args.Shift = args.TabLength;
            return;
        }
    }

Okay, so then I converted the code to VB, and now in my project it’s like this:

    'end of block
  If Regex.IsMatch(args.LineText, "(^\s*)End (Sub|Function|Property|Set|Class|Enum|Module|Structure|Namespace|Interface|Get)\b", RegexOptions.IgnoreCase) Then
     args.Shift = -args.TabLength
     args.ShiftNextLines = -args.TabLength
     Return
  ElseIf Regex.IsMatch(args.LineText, ".*(:|: |: )(End (If|While|Try|With|Using|SyncLock|Select)|EndIf|Next|Loop)\b", RegexOptions.IgnoreCase) Then
     args.ShiftNextLines = -args.TabLength
     Return
  End If
  'start of declaration
  If Regex.IsMatch(args.LineText, $"(^\s*|| )({dAttribute}) \b(Sub|Function|Property)\b ", RegexOptions.IgnoreCase) Then
     args.ShiftNextLines = args.TabLength
     Return
  End If
  If Regex.IsMatch(args.LineText, $"(^\s*|| )({dAttribute}) \b(Class|Enum|Module|Structure|Namespace|Interface|Get)\b|(Set\s*\()", RegexOptions.IgnoreCase) Then
     args.ShiftNextLines = args.TabLength
     Return
  End If
  ' then ...
  If Regex.IsMatch(args.LineText, "\b(Then)\s*\S+", RegexOptions.IgnoreCase) Then
     Return
  End If
  'start of operator block
  If Regex.IsMatch(args.LineText, "(^\s*|:|: |:  )(If|While|For|Do|Try|With|Using|SyncLock|Select)\b", RegexOptions.IgnoreCase) Then
     args.ShiftNextLines = args.TabLength
     Return
  End If

  'Statements else, elseif, case etc
  If Regex.IsMatch(args.LineText, "(^\s*|:|: |:  )(Else|ElseIf|Case|Catch|Finally)\b", RegexOptions.IgnoreCase) Then
     args.Shift = -args.TabLength
     Return
  End If

  'Char _
  If args.PrevLineText.TrimEnd().EndsWith("_") Then
     args.Shift = args.TabLength
     Return
  End If

...and the problem persists. Remembering that, I accept answers in C#.

  • 2

    Wouldn’t be idented instead of compensated?

  • Corrected.... Thank you

  • Which editor are you using? Visual Studio? Not quite clear in its explanation.

  • Yes, it’s Visual Studio 2015.

  • 1

    The question is confused. At first you say you are modifying the original project, but then it looks like you are building an editor that uses the component and your code is to configure the component within that editor. You can improve the question to make it clearer what this component is for and what part you’re in trouble with?

  • Sorry @Pagotti, I discontinued project development.

Show 1 more comment

1 answer

1

You just want to fix the identation?

Ctrl+K+D

If you want a tool that does this on multiple pages or even in the entire project, I recommend Codemaid, 100% free http://www.codemaid.net/

There is also the Resharper, but he gets paid, and using him just for that purpose is like buying a Ferrari to go to the Bakery.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.