Snapshot translate with search results

SyntaxEditor for WPF Forum

Posted 7 years ago by Martin - Blaise - Statistics Netherlands
Version: 16.1.0651


I have a list with searchresults, which are positions in files. I have added the snapshot to each result using this snapshot:


After clicking i jump to/select the specific position which works. Then i would like to translate this selection to the new snapshot, which messes up in case other, previous lines are changed in the meantime. Code:

public bool GotoPosition(IEditorPosition position, int selectCharacterCount) {
            TextPosition actiPos = new TextPosition(position.Line, position.Column);
            TextPosition endPoint = ActiveView.OffsetToPosition(this.ActiveView.PositionToOffset(actiPos) + selectCharacterCount);
            this.ActiveView.Selection.SelectRange(actiPos, endPoint);

            // reposition if snapshot changed
            var ep = (position as EditorPosition);
            if (ep != null && ep.SnapShot != null) {
                TextRange textRange = ActiveView.Selection.TextRange.Translate(ep.SnapShot, ActiveView.CurrentSnapshot, TextRangeTrackingModes.Default);

            return true;

So, the first SelectRange works, but the correction for changed snapshot messes up. 

Can you confirm that a translate can work over more than two versions of snapshots? (When more editing actions have been done)

Can translate handle new line etc, is there a method to Translate an position maybe?

So, in general, do you have a solution for my little problem:)

Thank you in advance,

Greets Martin

Comments (2)

Answer - Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA

Hi Martin,

In your code, I believe you are translating to the old snapshot, which opposite of what you want to do.

In our SearchFindResults QuickStart, you can see our implementation of this sort of thing which seems to work fine with edits done in between when the search was made and the jumping to a search result.

We effectively do:

    editor.ActiveView.CurrentSnapshot, TextRangeTrackingModes.Default).TextRange);

As long as you store a TextSnapshotRange in your results and swap that in place of the "result.FindSnapshotRange" then it should work.

Actipro Software Support

Posted 7 years ago by Martin - Blaise - Statistics Netherlands

That worked, just other way around:)


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