Search result in a collasped region

SyntaxEditor for WPF Forum

Posted 14 years ago by Mick George - Senior Software Engineer, CNC Software, LLC
Avatar
Product Version: SyntaxEditor v10.1.520

Hi, I am trying to determine if a search result is within a collapsed region and if so automatically expand that region so the user can see the result.

I have tried using the ISearchResultSet from a IEditorViewSearcher FindNext method in conjunction with the current documents OutliningManager to determine the outlining state but I seem to be missing something, or should I be looking to the SyntaxEditor ViewSearch event?

Thanks in advance.

Comments (5)

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

You can use the view's ICollapsedRegionManager to determine if text is hidden. The view.CollapsedRegionManager.GetCollapsedRange(TextSnapshotOffset) method would probably be what you want.


Actipro Software Support

Posted 14 years ago by Mick George - Senior Software Engineer, CNC Software, LLC
Avatar
Thank you, that worked out perfectly.
Posted 14 years ago by Mick George - Senior Software Engineer, CNC Software, LLC
Avatar
I hate to resurrect an old post but I have been getting some odd text display issues when a search result is within a collapsed region. I have linked an Image showing the issue.

When this code executes it raises my GetCollapsedContent override in my PostBlockCommentNodeDefintion shown below:

 public override object GetCollapsedContent(IOutliningNode node)
        {
            // Get the node's snapshot range
            TextSnapshotRange snapshotRange = node.SnapshotRange;

            // Use the text in the first line
            int lineEndOffset = snapshotRange.StartLine.EndOffset;
            return snapshotRange.Snapshot.GetSubstring(new TextRange(snapshotRange.StartOffset, lineEndOffset)) + "[..]";
        }
My code below is used to check and expand a region.


public void SyntaxEditor_ViewSearch(object sender, RoutedEventArgs e)
{

 ISearchResultSet resultSet = args.ResultSet;

                SyntaxEditor editor = sender as SyntaxEditor;
                
                if (null != resultSet)
                {
                    // Get the region manager to determine if this result is within a collapsed region
                    ICollapsedRegionManager regionManager = editor.ActiveView.CollapsedRegionManager;

                    // get the snapshot
                    ITextSnapshot snapShot = editor.ActiveView.CurrentSnapshot;

                    // Store the offset of the current word
                    TextSnapshotOffset offset = new TextSnapshotOffset(snapShot, editor.ActiveView.GetCurrentWordTextRange().StartOffset);

                    TextSnapshotRange textSnapshotRange = regionManager.GetCollapsedRange(offset);

                    // Check
                    if (!textSnapshotRange.IsDeleted)
                    {
                        // This word is hidden within a collapsed region
                        IEditAction action = new ToggleOutliningExpansionAction();

                        // Open the region
                        if (action.CanExecute(editor.ActiveView))
                        {
                            editor.ActiveView.ExecuteEditAction(action);
                        }
                    }
                }

                editor.Focus();

}

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

We haven't seen that happen before. Can you put together a very simple new sample project that shows the issue and email it to our support address (with renamed file extension) so that we can see it and debug it? Please reference this post in your reply. Thanks!


Actipro Software Support

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Thanks for the sample. We've updated the code for the next maintenance release to properly expand any collapsed nodes that contain the selection.


Actipro Software Support

The latest build of this product (v24.1.2) was released 1 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.