Forcing StructureMatcher to run Match method

SyntaxEditor for WPF Forum

Posted 10 years ago by Scott Currie
Version: 13.2.0590
Avatar

I have taken your SimpleStructureMatcher sample and added functionality to detect XML start/end tags and highlight them both when either is clicked.

I want the entire start tag to be highlighted - including the attributes, etc.  But when you click outside of the tag part (i.e. XmlTokenId.StartTagStartDelimiter, XmlTokenId.StartTagName), I'd like the Match method to rerun so that I can turn off the highlighting.

Unfortunately, the StructureMatcher does not re-run the Match method if you click anywhere within an existing StructureMatchResult range.  Is there a way I can circumvent that check and force it to always run?

Comments (4)

Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Scott,

It looks like the DelimiterHighlightTagger.OnViewSelectionChanged method (which is private) currently only resets the highlights in certain scenarios, such as when the caret is outside the current range.  But note that the StructureMatchResult that you create has a MatchEdges property that you can alter to affect which edges are considered part of the highlight.  It defaults to Both, but you could change that as needed.  That might get you what you need.


Actipro Software Support

Posted 10 years ago by Scott Currie
Avatar

I tried all of the permutations of MatchEdges, but it looks like it's missing the option that would help me.  Specifically - NoneNotEvenMiddle.  Or perhaps NoMiddleButEdgesAreFine.  It seems intent on matching the middle of the range, regardless of the MatchEdges setting.

Is there any workaround you can think of?  If I add a SelectionChanged event handler at the document level, is there any way I can reset the structure matchers result set externally?  Even if I have to use reflection, I'm fine with that, since I can do some fast token id checking to prevent the reflection call from happening except when it really needs to.

Posted 10 years ago by Scott Currie
Avatar

Ok, I think I've found a workaround, but it's really nasty.  Could you advise me about whether this is totally stupid or if there is a better workaround?

Basically, the problem is that your DelimiterHighlightTagger.OnViewSelectionChanged will never reset the highlights for clicking in the middle, regardless of StructureMatchEdges settings.  So, I created a range for the *beginning* of the start tag, and a range for the end tag (much like before).  But then I create as many 1 character ranges as I need to cover every character of the contents of the start tag.  Since these 1 character ranges lack a middle, the StructureMatchEdges.None setting has the desired effect.

I suppose I might be able to decrease the StructureMatchResult count by doing 2 character ranges, but that would be the limit.

Thoughts?

Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Scott,

Right, the DelimiterHighlightTagger.OnViewSelectionChanged is where all of the determining-whether-to-reset-highlights logic occurs.  I guess I'm a bit confused by your scenario though.  Since if you are highlighting the start and end tag, I would think MatchEdges.None would reset everything as you move outside the tag (like before the starting '<'. 

Or do you mean you want it to reset the highlights even when you click on an attribute within a highlighted start tag, perhaps to remove the highlights on the containing start tag?

While what you are doing might work, I wouldn't recommend it.  I'd rather see us come up with an option or overridable method for you to take advantage of.


Actipro Software Support

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.