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:
It’s like this:
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#.
Wouldn’t be idented instead of compensated?
– pnet
Corrected.... Thank you
– CypherPotato
Which editor are you using? Visual Studio? Not quite clear in its explanation.
– brazilianldsjaguar
Yes, it’s Visual Studio 2015.
– CypherPotato
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?
– Pagotti
Sorry @Pagotti, I discontinued project development.
– CypherPotato