PositionToOffset consider tab character as 4 characters

SyntaxEditor for WPF Forum

Posted 8 years ago by Banukobhan Nagendram
Version: 15.1.0624
Platform: .NET 4.5
Environment: Windows 10 (64-bit)

I used the function int PositionToOffset(TextPosition position) from ITextSnapshot interface to convert text position to offset.

	int i = 0;
	int k = 5;

 My text editor has above text. The cursor position is infront of character 'i' in first line. (Text position line=0, column=8).

PositionToOffset return the value 8 as offset. (Consider tab character as 4 characters/offsets)

But when I'm getting it from editor caret position, offset is 5. (path => SyntaxEditor.Caret.Offset. It is giving Offset as 5.) (Consider tab character as 1 character/offset)

This is inconsistent. Please fix this issue.


Is there anyway to get the offset from TextPosition, with consider tab character as 1 offset?


Comments (1)

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

Hello, I think you might be doing something wrong here and are confusing columns and characters.  TextPosition is a pair of Line and Character values.  For before the "i", the offset would be 5 and the TextPosition would be {Line=0, Character=5}.  The Column (calculated separately and different from the TextPosition.Character) would be the only thing returning 8 there.  Characters are based on real characters (meaning tab == 1 character), while Columns are based more on visual alignment (meaning tab = 4 columns).

Actipro Software Support

The latest build of this product (v24.1.2) was released 3 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.