SyntaxEditor - Move/Select to Matching Bracket

by Avatar Bill Henning (Actipro) - 5 comments
Friday, September 7, 2012 at 1:39pm

BlogPostBanner

As seen in yesterday's post, delimiter (bracket) highlighting is coming to the WPF and Silverlight SyntaxEditor controls in the 2012.2 version (due very soon). 

A new language service that was described yesterday was a structure matcher service.  This allows delimiter sets to be located.  When one of these is registered on a language, SyntaxEditor automatically gains a new feature:  move/select to matching bracket.

UPDATE:  Version 2012.2 is live and available for download now.

Select to Matching Bracket Example

Let's take a look at how this all works.  Say we have this scenario in SyntaxEditor where the caret is next to a parenthesis. 

SelectToBracket1

Notice that the bracket highlight is not visible because the caret is on the inside of the parenthesis and the highlights for this language are told to only show when the caret is on the outside of a parenthesis.

Now we press Ctrl+Shift+] and voila, the structure matcher returns the nearby delimiters to SyntaxEditor, and the full delimiter range is selected.

SelectToBracket2

So you may be asking, how did that work, when delimiter highlighting didn't register the parenthesis as a valid delimiter?  We designed the structure matcher so that an option can be passed asking it to be more liberal in its matching algorithms.  So while the delimiter highlighting matching logic for a language may have very specific locations a match can occur, other features like move/select to matching bracket can find matches that are anywhere next to the caret.

On a side note, the hotkeys for moving (Ctrl+]) and selecting (Ctrl+Shift+]) to the matching bracket only work in WPF since Silverlight doesn't allow us to watch for that key sequence being pressed.  However you can still provide this functionality to customers via a menu item in Silverlight.

Summary

Move and select to matching bracket is some handy functionality when editing code blocks.  We're excited to offer it in the 2012.2 version.

TaskDownload TaskLiveDemo TaskBuyNow

Actipro's WPF Controls

Over 100 UI controls for building beautiful Windows Presentation Foundation desktop apps.

Learn More

Over 100 UI controls for building beautiful Windows Presentation Foundation desktop apps.

Includes editors, docking windows, MDI, property grids, charts, tree controls, ribbons, gauges, themes, and much more.

Learn More Download Free Trial

Comments (5)

Posted 12 years ago by Helmut Zörrer
Avatar
Hi Bill, Ctrl+Shift+] doesn't work for me per default in your 'syntax editor SDI Code Editor' sample nor in my application. do i have to specify something additional? ?implement a 'structure matcher service'? g Helmut
Posted 12 years ago by Bill Henning (Actipro) - Actipro Software LLC
Avatar
Hi Helmut, As noted above, that key sequence won't work in Silverlight. But in WPF it should work in languages that support the structure matcher out of the box. So in WPF it works by default with our C#/VB languages from the .NET Languages Add-on. I just tried it.
Posted 12 years ago by Helmut Zörrer
Avatar
Hi Bill - only WPF and C# for me ;-) It doesn't work at my pc. i downloaded the new 2012_2 edition. Start the Samples Browser go to 'Syntax Editor' start the 'Updated 'SDI code editor'. Klick 'run external Code' go to line public static void Main(string[] args) place the cursor before the last bracket. args***CURSOR_HERE***) press CTRL SHIFT ] (on my keyboard this means press the ')9]' key and nothing happens.
Posted 12 years ago by Bill Henning (Actipro) - Actipro Software LLC
Avatar
Hi Helmut, I just did the same and it worked fine. It must be the keyboard shortcut that is causing you problems due to culture differences. Just so you know, our default shortcut is defined like this, so you can change it as needed in the SyntaxEditor.InputBindings collection: this.InputBindings.Add(new KeyBinding(EditorCommands.SelectToMatchingBracket, Key.OemCloseBrackets, ModifierKeys.Control | ModifierKeys.Shift));
Posted 12 years ago by Helmut Zörrer
Avatar
Hi Bill, THX again :-) this.InputBindings.Add(new KeyBinding(EditorCommands.SelectToMatchingBracket,Key.D9, ModifierKeys.Control | ModifierKeys.Shift)); Now does the thing similar to yours :-) BTW: on my keyboard i have to press ALT and the ')9]' Key to get an ']'. normally pressing ths key gives a '9' But the combination CTRL SHIFT ALT ')9]'-Key didn't work either - no idea how i could get the Key.OemCloseBrackets without an 'ALT' ...

Add Comment

Please log in to a validated account to post comments.