I am evaluating Syntax Editor for WPF as part of a UI for one of my companys' products.
I am having trouble understanding the CR-NL to CR mapping.
What I want to do is to programmatically change a section of text within a C# class inside SyntaxEditor. However the offsets for the CR-NL Ast model are different than those I need to use against the "internal" CR delimited model inside the parser.
From what I can read from the documentation, I should do the following.
1. // Get a snaphot of the current document
ITextSnapshot snapshot = MyDocument.CurrentSnapshot;
2. // Get the Ast tree
IAstNode codeDom = ((IDotNetParseData)parseData).Ast;
3. // work through the code DOM until I find the Ast node I need
// code not shown
QueryExpression whatIwantToReplace = ParsingUtils.GetChildOfType<QueryExpression>(this.QueryExpressionContainer);
4. // create a text range matching the whole of the query expression.
TextRange tr = new TextRange((int)whatIwantToReplace .StartOffset, (int)whatIwantToReplace .EndOffset);
5. // create a text change and apply it
TextChangeOptions options = new TextChangeOptions();
options.OffsetDelta = TextChangeOffsetDelta.SequentialOnly;
options.RetainSelection = true;
ITextChange change = this.QueryModel.TextDocument.CreateTextChange(TextChangeTypes.Replace, options);
6. // Apply the change
change.Apply();
The problem of course is that the Ast node offsets are against a text document which has CR-NL whereas when I apply the change it is being applied against the internal parser document which only has CR NOT CR-NL and hence replaces the wrong parts of the text document.
Q: How do i convert my Ast begin and end offsets to something that is valid to use against the CR NOT CR-NL document?
I have tried everything I can think of, read everything I can and still can't find a way.
Any help greatly appreciated.
I am having trouble understanding the CR-NL to CR mapping.
What I want to do is to programmatically change a section of text within a C# class inside SyntaxEditor. However the offsets for the CR-NL Ast model are different than those I need to use against the "internal" CR delimited model inside the parser.
From what I can read from the documentation, I should do the following.
1. // Get a snaphot of the current document
ITextSnapshot snapshot = MyDocument.CurrentSnapshot;
2. // Get the Ast tree
IAstNode codeDom = ((IDotNetParseData)parseData).Ast;
3. // work through the code DOM until I find the Ast node I need
// code not shown
QueryExpression whatIwantToReplace = ParsingUtils.GetChildOfType<QueryExpression>(this.QueryExpressionContainer);
4. // create a text range matching the whole of the query expression.
TextRange tr = new TextRange((int)whatIwantToReplace .StartOffset, (int)whatIwantToReplace .EndOffset);
5. // create a text change and apply it
TextChangeOptions options = new TextChangeOptions();
options.OffsetDelta = TextChangeOffsetDelta.SequentialOnly;
options.RetainSelection = true;
ITextChange change = this.QueryModel.TextDocument.CreateTextChange(TextChangeTypes.Replace, options);
6. // Apply the change
change.Apply();
The problem of course is that the Ast node offsets are against a text document which has CR-NL whereas when I apply the change it is being applied against the internal parser document which only has CR NOT CR-NL and hence replaces the wrong parts of the text document.
Q: How do i convert my Ast begin and end offsets to something that is valid to use against the CR NOT CR-NL document?
I have tried everything I can think of, read everything I can and still can't find a way.
Any help greatly appreciated.