Am I doing something wrong?

SyntaxEditor for Windows Forms Forum

Posted 19 years ago by Karl Grambow
Avatar
I'm handling the SmartIndent event and traversing (backwards) through the previous line to see if I find any matching tokens. I then check to see whether they are BracketHighlighted and do some other stuff based on whether I can find their matching token.

My problem is this, if the matching token is not the last token before the line-end, it's BracketHighlighting value shows up as false, even though it is highlighted.

Here's some of my code to illustrate the problem:
       
        oToken = oStream.ReadReverse

        'read the tokens along the currentline
        Do Until oToken.Key = "LineTerminatorToken"

            'if we find a begintran token, get out
            If oToken.Key = "BeginToken" Then Exit Do

            oToken = oStream.ReadReverse
        Loop

        'below returns true if the line being traversed reads (ignore quotes):  "begin tran"
        'below returns false if the line being traversed reads (ignore quotes):  "begin tran fred"

        'however, in both cases oToken.Key = "BeginToken"

        If editor.SelectedView.BracketHighlighting.IsHighlightedBracket(oToken) Then
            'do some stuff
        End If

So, it looks like, even though oToken is the same in both cases, IsHighlightedBracket is not returning true when the supplied oToken should be being tracked.

I'm obviously doing something wrong or mis-interpreting how BracketHighlighting works but I can't figure out what. Any help is appreciated.

Karl

Comments (5)

Posted 19 years ago by Karl Grambow
Avatar
Ok, I did some more playing around and I figured what's wrong.

The IsHighlightedBracket only returns true if the caret is sitting at the oToken.Offset, which is contrary to the way I understood it from the documentation. In the documentation: IsHighlightedBracket Gets whether the specified Token is a bracket that is being tracked.

I assumed that a token was tracked regardless of whether the caret was sitting at the token or not. If the caret needs to be next to the token it seems unnecessary to pass a token value to IsHighlightedBracket method if the token doesn't really determine whether the return value is true or false. Maybe I'm still getting something wrong here.

Anyway, I've managed to work around this now by moving the caret to the token's offset before I evaluate whether it's being tracked or not. And this works.

However, the side-effect of this is that you see the caret moving backwards and forwards which doesn't look nice.

Is there a neater way for me to achieve what I want? Which is basically to find out whether a given token is being tracked, and subsequently find that token's matching token, regardless of where the caret sits.

Thanks,

Karl
Posted 19 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
In v4.0 we're adding some things in Token and in TextStream to make this sort of thing much easier. But anyhow, in v3.1, you can look at the LexicalPatternGroup for a Token. That has properties like EndBracket and StartBracket. If EndBracket is filled in, you know the token is a start bracket. And vice versa.


Actipro Software Support

Posted 19 years ago by Karl Grambow
Avatar
Ah, of course, that's good idea.

I guess I'd still have a problem trying to find the matching bracket without having the caret next to the start bracket. I imagine I'll have to read forwards and find a token with a StartBracket property but I have to be careful that it isn't the end bracket for a different start bracket.

I don't suppose there's an easy way to do that? SyntaxEditor does pretty much everything else! :).

At least I now have an easy way to find the start bracket.

Thanks,

Karl
Posted 19 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
TextStream has a method called GoToNextToken with an overload where you can pass it a key. It will jump to the next token with that key. That may help.


Actipro Software Support

Posted 19 years ago by Karl Grambow
Avatar
Thanks,

That's really good to know.

Karl
The latest build of this product (v24.1.1) 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.