Using multiple Formatter on Xml Documents

SyntaxEditor for WPF Forum

Posted 6 years ago by Younes Müller
Version: 17.2.0662
Avatar

Hello,

I am trying to write a custom Formatter for Xml-Files.

My goal is to align the properties in each line.

<Tag1 Property1=".."
  Property2=".."/>

<Tag1 Property1=".."
      Property2=".."/>

 So in this example I want to Format the first tag into the second.

I have already created a custom TextFormatter.

As I purchased the Web-Languages Plugin, I want to use the prewritten XmlTextFormatter.

public class MyFormatter: ITextFormatter
{
  private XmlTextFormatter xmlFormatter;
  //...
  public void Format(TextSnapshotRange snapshotRange)
  {
    xmlFormatter.Format(snapshotRange);
    //my textchanges
  }

There is no problem, if I leave out the xmlFormatter.Format. It behaves as I wish.

However if I try to change the snapshot after applying the formatter the document gets ripped apart near the changes I apply.

I assume, that the offsets/line positions of the snapshot are somehow faulty, after using the xmlFormatter.

Is there a way to restore a state, where I can continue formatting the file?

 

Edit: I gave you the wrong version. I am using: v13.2.0590 on 09.09.2013

 

 

Thank you very much and kind regards,

Younes Müller

[Modified 6 years ago]

Comments (1)

Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

It looks like you are making a custom text formatter service that calls ours first and then you want to modify the result.  What's happening behind the scenes is that a new snapshot is created by ours since it's doing a text change.  After you call ours, you can get the new snapshot with:

snapshotRange.Snapshot.Document.CurrentSnapshot

Then you can translate the snapshot range to that new snapshot if you'd like and operate over that range.  Any text change you make should be based on that new snapshot too.

I hope that helps.


Actipro Software Support

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