Having problem with AutoCaseCorrect and CaseCorrectText

SyntaxEditor for Windows Forms Forum

Posted 14 years ago by Karl Grambow

I'm not sure if it's me that's doing something wrong or if I've stumbled onto a bug (probably me).

I'm basically loading sql server stored procedures into syntax editor and I'm providing an option to either have the key words in uppercase or lowercase.

I've run into a couple of problems.

1) When I'm opening a document that has AutoCaseCorrectEnabled=True everything works fine. However, if I have it set to false I'd expect the relevant key words to be in lowercase but they're not. Any key words that were in uppercase to begin with stay in uppercase.

2) The second problem I'm having has to do with changing an open, syntaxeditor document from AutoCaseCorrectEnabled=true to false. It seems to work fine when going from lowercase to uppercase but it doesn't work when trying to convert existing uppercase key words to lowercase.

Here's a snippet of the code I'm using:

'change lowercase key words to uppercase
CurrentEditor.Document.AutoCaseCorrectEnabled = True 'this works fine
CurrentEditor.Document.CaseCorrectText(0, CurrentEditor.Document.Lines.Count - 1)


'change uppercase key words to lowercase
CurrentEditor.Document.AutoCaseCorrectEnabled = False 'but this doesn't work 
CurrentEditor.Document.CaseCorrectText(0, CurrentEditor.Document.Lines.Count - 1)

Comments (7)

Posted 14 years ago by Karl Grambow
Just noticed something.

Let's take the key word, SELECT.

If I defined that in my language definition file as lowercase select then AutoCaseCorrectEnabled = True will not change it to uppercase. And vice-versa, which is why the second option above was not working. I have defined all of my key words in uppercase so they cannot be changed to lower case using AutoCaseCorrectEnabled.

Looking at it this way makes sense now. AutoCaseCorrectEnabled only matches the case to how I defined it in the language definition file so my code above was never going to work how I intended.

That said, is there any other way I can change the case of my defined key words?

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Hi Karl,

Yes you figured it out, it corrects it to how you defined it in the language definition. This is useful for languages like VB where you make keywords in mixed case like "Dim" and you want case corrected to that.

One thing you could do is set the language's IsUpdating flag to true, then update all the patterns to switch them to upper/lowercase and then set IsUpdating to false. That would probably let you get your desired functionality based on a user preference.

Actipro Software Support

Posted 14 years ago by Karl Grambow
Thanks for the reply.

I haven't had to play around with editing languages at runtime but I'm guessing that I'll need to:

1) retrieve the entire Explicit Patterns for a given TokenKey, and
2) after changing it to lowercase, write it back to the language for the given TokenKey.

Could you provide the code (or the methods that I can use) to achieve 1 and 2? If the code is too involved just let me know what methods to look for in the help or sample application.


Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
It should be easy... just find the LexicalPatternGroup(s) that you want to modify. After you get a reference to that, enumerate through the collection and change the LexicalPattern.Pattern property to either upper or lowercase versions of each pattern. Remember that LexicalPatternGroups are in the LexicalState.PatternGroups collection, so you need to get the proper LexicalState from the SyntaxLanguage. The state you want is most likely the default one, stored in SyntaxLanguage.DefaultLexicalState.

Remember to surround the whole loop with the proper SyntaxLanguage.IsUpdating calls.

Actipro Software Support

Posted 14 years ago by Karl Grambow
Thanks a lot! That works perfectly as you described.

I'm now having problems with something else though and I think it's my lack of understanding about how AutoCaseCorrect is supposed to work. It's been a long week too and my mind isn't working right either.

After updating the language I switch on AutoCaseCorrect and perform a CaseCorrectText on the document. However, unless I switch AutoCaseCorrect off after performing the update I get weird results: like some lines in the document get partially updated, others don't. But the moment I place the caret on a given line, that line gets updated to reflect the correct case.

I've included the code below for you to look at just in case you can spot anything obvious that I'm doing wrong. It's really the last line that is fixing the problem but then of course I don't have AutoCaseCorrect enabled. If I don't include the last line then it doesn't work:

Dim EnableUpperCase As Boolean 'I get this value from the calling procedure

'start updating the document language
CurrentEditor.Document.Language.IsUpdating = True

                Dim PatternGroup As LexicalPatternGroup

                'lets go through each pattern group in the default lexical state pattern groups
                For Each PatternGroup In CurrentEditor.Document.Language.DefaultLexicalState.LexicalPatternGroups

                    'if we find the patter group we're looking for
                    If PatternGroup.TokenKey = "ReservedWordToken" Or _
                        PatternGroup.TokenKey = "FunctionToken" Or _
                            PatternGroup.TokenKey = "DataTypeToken" Or _
                            PatternGroup.TokenKey = "OperatorToken" Then

                        'let's get each pattern
                        For Each Pattern As LexicalPattern In PatternGroup

                            'and change the individual patterns to upper or lower case
                            If EnableUpperCase = True Then
                                Pattern.Pattern = UCase(Pattern.Pattern)
                                Pattern.Pattern = LCase(Pattern.Pattern)
                            End If


                    End If


                'finish updating
                CurrentEditor.Document.Language.IsUpdating = False

                'enable autocasecorrect
                CurrentEditor.Document.AutoCaseCorrectEnabled = True

                'and casecorrect the document
                CurrentEditor.Document.CaseCorrectText(0, CurrentEditor.Document.Lines.Count - 1)

                CurrentEditor.Document.AutoCaseCorrectEnabled = False

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
The problem here might only be that the document is not repainted. Instead of setting that property off, try doing CurrentEditor.Invalidate() and let me know if that fixes it.

Actipro Software Support

Posted 14 years ago by Karl Grambow
Absolutely perfect. That was it.

Thanks alot for your help.

The latest build of this product (v2018.1 build 0341) was released 3 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.