get ICaret.DisplayCharacterColumn is higher than 9600

SyntaxEditor for WPF Forum

Posted 4 years ago by Banukobhan Nagendram
Version: 15.1.0623
Avatar

In Syntax Editor, I'm trying to get the current caretPosition and display the line and column number.

 

ICaret caretPosition=editor.Caret;

int line=caretPosition.Position.DisplayLine;

int column=caretPosition.DisplayCharacterColumn;

 

I have a problem, when the length of the line exceed 9600 characters.

Lets assume 12th line have 10,000 characters, after 9600 characters line wrapped and display as next line.

If I select 12th line and 9601 character, then caret position returns line = 12 and column = 1. But the expected column is 9601.

How to resolve this issue.

Note: But the Visual Studio allow to have more than 9600 characters in a single line.

Thanks in advance.

[Modified 4 years ago]

Comments (3)

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

We are forced to wrap the line at a certain point even if word wrap is off because if WPF tries to render past a certain X location, it throws an exception.  The wrapping prevents that exception from occurring, and that is why this scenario happens. 

The column is being reported correctly in this scenario though.  Column is more of where the caret is visually, while Character tells you where the actual character is on the document line.


Actipro Software Support

Posted 4 years ago by Banukobhan Nagendram
Avatar

But there is another caret position with exactly same line and column no. (eg line = 12, column = 1. 1st character and 9601st character both characters have the same values of line and column)

The wrapped 3rd, 4th lines also have the same line and column values.

How shall I differeniate between these caret positions, which have same line and column values.

I need to get the correct column no. (eg: If wrapped as 2nd line, then 9600+1 = 9601)

Is there any way to get the column no?

[Modified 4 years ago]

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

The Column number is a visual X position based on the average character width.  Since the line is being wrapped here, a small column number is correct at the start of both the unwrapped and subsequent wrapped lines.  Word wrapped lines (when you have that feature enabled) behave the exact same way, and VS also shows Columns as we do where each wrapped line starts at column 1.

The Character number on the other hand designates the logical character position within the current document line.  A combination of those three values (Line, Column, Character) gives you a unique position, even in this scenario.  If you only show Line and Column alone, as you saw there will be duplicates in this scenario.


Actipro Software Support

The latest build of this product (v2019.1 build 0683) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.