Snapshot translate with search results

SyntaxEditor for WPF Forum

Posted 2 years ago by Martin de Jong - Statistics Netherlands
Version: 16.1.0651
Avatar

Hi

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

ActiveView.CurrentSnapshot.SnapshotRange.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);
                ActiveView.Selection.SelectRange(textRange);
            }

            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 2 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

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.Selection.SelectRange(result.FindSnapshotRange.TranslateTo(
    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 2 years ago by Martin de Jong - Statistics Netherlands
Avatar

That worked, just other way around:)

Thanks

The latest build of this product (v2019.1 build 0683) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.