How can I convert document.text offsets to document offsets?

SyntaxEditor for Windows Forms Forum

Posted 10 years ago by Craig - Varigence, Inc.
Version: 4.0.0284
Avatar
I'm trying to use the InsertText and ReplaceText functions in SyntaxEditor.Document but the offsets I have come from SyntaxEditor.Document.Text. Is there a way to convert the offsets from Document.Text, so they consistently work with the Document functions?

Thanks,

-Craig

Comments (5)

Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Craig,

Document.Text restores \r\n line terminators. You can use the GetText method to specify the line terminators to use. If you want to match how we internally track them, you'd use Newline. But you also may want to consider using a TextStream to do text scanning instead (via Document.GetTextStream) since that lets you navigate the text without actually having to construct a huge string.


Actipro Software Support

Posted 10 years ago by Craig - Varigence, Inc.
Avatar
I don't think that answers my question - let me provide some more info.

I'm using InsertText and DeleteText to synchronize my syntaxeditor's content with some textboxes (and we're not at a time in development for altering this approach). I like comparing my UI text changes with SyntaxEditor.Document.Text since the offsets match until I find my first char difference (my source text also has line terminators).

However, I've found that using the offset from Document.Text doesn't work in InsertText and DeleteText - they seem to want offsets that exlcude the line terminators. I tried calculating the line terminators manually and subtracting from my offset but that didn't work. Thus, I was wondering if there's an appropriate function that will do that conversion or if I'm stuck with the manual calculation approach.

Thanks again,

-Craig
Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Ahh I see... unfortunately you'd have to do it manually if you only have offsets. If you have line/col then you can use methods like Document.PositionToOffset, etc. to convert between line/col and offset. So that would be the best way to go if you have that sort of data available.


Actipro Software Support

Posted 10 years ago by Craig - Varigence, Inc.
Avatar
When we use the Xml Addin for the Syntax Editor, is counting newlines the only thing I need to worry about or might there be other characters that would affect the offset?

Thanks,

-Craig
Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
The line terminator conversion is the only thing we do that would affect offsets.

The XML add-on when doing XML validation may insert a namespace to the code being scanned for validation if you use a certain option but the error results we get back should compensate for the number of characters inserted so that you'd never know the difference.


Actipro Software Support

The latest build of this product (v2018.1 build 0342) was released 11 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.