old snapshot createTextChange

SyntaxEditor for WPF Forum

Posted 23 days ago by SPF - Appeon
Version: 22.1.2
Avatar

Can I create "textchange" based on the old "snapshot" and operate on it?

For example, in "completionsession", I need to create textchange based on "CompletionSession. SnapshotRange. Snapshot" to change the text.

Comments (5)

Posted 23 days ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

Yes, text changes are created via the ITextSnapshot.CreateTextChange method.  Then when a text change is applied, it translates the change's operations' text ranges from that original snapshot to the document's current snapshot.


Actipro Software Support

Posted 22 days ago by SPF - Appeon
Avatar

You don't seem to understand what I mean:

I now have a scenario, the current ' CurrentSnapshot Text == "" ', when I enter 'd' , the "CompletionSession" pops up, then enter 'o' and 'c', and then enter.

At this time, 'session. View. Currentsnapshot Text =="doc" '、'Session.SnapshotRange.Snapshot. Text == "d" '。

At this time, I want to do text replacement based on "session. Snapshotrange. Snapshot", replace'd 'with' document 'and apply it; Tthe result I want is 'view.CurrentSnapshot.Text == "document" '.

This is how I should do the text replacement operation.

[Modified 22 days ago]

Posted 22 days ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

Per our previous reply, you can create a text change off of any snapshot (e.g. Session.SnapshotRange.Snapshot) you wish.  It will translate the operation text ranges to the current snapshot.  Have you tried that approach, and if so, did you experience any problems?

For instance, it could be that after the replace, you end up with "documentoc".  Is that the case?  If so, that might be because our text change translation to the current snapshot uses default tracking mode options, whereas when working with Session.SnapshotRange, we usually use the ExpandLastEdge tracking mode that will include subsequent typing of "o" and "c":

var snapshotRange = this.SnapshotRange.TranslateTo(view.CurrentSnapshot, TextRangeTrackingModes.ExpandLastEdge);

I would suggest using that custom translation line to get the snapshot range relative to the current snapshot, and then replace on the current snapshot.


Actipro Software Support

Posted 21 days ago by SPF - Appeon
Avatar

Yes, I just encountered the problem that the final result is "documentoc". How do I deal with this situation.

Our scenario is that when I input "a", I will get the text data of the current replacement, including the scope and content of the replacement. These data are generated based on "CompletionSession. Snapshotrange", and can only be applied to this "Snapshot".

If it is applied in the "snapshot" with "o" and "c" entered later, these data will be inaccurate.

Please tell me specifically what to do. The above code can't solve my problem.

Posted 21 days ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Text changes can only be applied to the document's current snapshot.  If you create a text change for an older snapshot, it will use Default tracking mode options to translate the text ranges to replace in each operation to the document's current snapshot.  But the Default tracking mode doesn't expand to include newly-typed text, which leads to the problem scenario here.

That's why in the previous reply, I suggested that you use that code line to manually translate the Session.SnapshotRange to the current snapshot on your own using ExpandLastEdge tracking mode (instead of the normal Default tracking mode).  The snapshotRange variable result will then have the snapshot range you want, but based on the current snapshot, and including newly-typed characters.  It will be the same snapshot range that would be replaced by a completion list commit.  Use that as the snapshot range to replace with your "document" text and then you should have a "document" final result instead of "documentoc".


Actipro Software Support

The latest build of this product (v22.1.3) was released 20 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.