Problem with Fast Colored TextBox (indentation)

9

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

  

Instead of looking like this:

  

You'relikethis:

And the rest of the code inside that FCTB is indented forward. Here is the original code of the paragraph VB (In C #) (Extracted from 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;
        }
    }

Ok, so that's when I converted the code to VB, and now it looks like this in my project:

    '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 #.

    
asked by anonymous 05.06.2015 / 07:10

1 answer

1

Do you just want to correct the indentation?

Ctrl+K+D

If you want a tool that does this on several pages or even the entire project, I recommend CodeMaid, 100% free link

There is also Resharper , but it is paid, and using it just for that purpose is like buying a Ferrari to go to the bakery.

    
19.05.2017 / 20:02