Scrolling to selection after FindNext

SyntaxEditor for WPF Forum

Posted 12 years ago by RS
I'm implementing our Find Replace functionality with SyntaxEditor and have hit a minor problem.

After executing a FindNext (on activeview.currentsnapshot - is that the way I should be doing it) I set ActiveView.Selection.TextRange to the first find result TextRange and then call ActiveView.Scroller.ScrollToCaret. This sometimes leaves the selection off the edge of the visible area - is there a better way to ensure the selection is visible (preferably in the middle of the view), or perhaps another way to call FindNext that takes care of this?

The behavior of ReplaceNext seems a bit odd in that it does a find and then replaces the first find - is there functionality equivalent to clicking Replace on a Find Replace dialog - that replaces the selection if it's the text being searched for and then moves the selection point to the next result. Perhaps I'm missing the idea of ReplaceNext?


Comments (3)

Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
The find/replace model you are using is based on the document model and is the low-level find/replace code. We are currently working (today actually) on the view-based find/replace model that will essentially layer on top of the core document model and should provide all the view-related implementation code for you. This is one of the few remaining areas before a public beta can be released.

We may post a blog entry shortly on where we're going with it and will ask for input on some ideas so please keep an eye on the blog.

As for a more advanced ScrollToCaret that does centering, we don't have that yet however if you have any specific suggestions on what you'd like to see and what parameters you'd want to pass, please do post your ideas!

Actipro Software Support

Posted 12 years ago by RS
Great, I'll put this on the back burner for now then until the view based find and replace in there.

The behavior I'd like to implement for scroll to selection is primarily to ensure that the selection is visible. Beyond that, it would be nice if when a scroll operation is necessary to show the selection, the resulting vertical position in the view of the selection was consistent (to avoid having to scan around to see where the selection is). I'm thinking central to the view (vertically) would be good, but only if scrolling is necessary for the selection to be visible - that seems to be the behavior in VS during find and replace.


Posted 12 years ago by Boyd - Sr. Software Developer, Patterson Consulting, LLC
I just posted some thoughts
on this topic that I split to another thread because it involved more than Find/Replace.
The latest build of this product (v2020.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.