Cursor Pos from a Token?

SyntaxEditor for Windows Forms Forum

Posted 14 years ago by John
Avatar
How can you get the actual caret position from a token? All of the offsets and positions give the token index or what not, but nothing I can see gives me the cursor position.

Comments (7)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
I assume you mean the x,y pixel location? In the SyntaxEditor world, that is called a "location".

Check out the "General Features / Offset, Positions, and Locations" topic in the documentation. It tells how to get it.


Actipro Software Support

Posted 14 years ago by John
Avatar
I replied and it looks like my reply got lost somewhere, so I apologize if this gets repeated.

Anyway, what I really meant was the character offset from the Token. I thought this should be the Token.Startoffset. Which it is. But the thing is I was using this in conjuction with SelectedView.Selection.StartOffset;

So here lies the problem, if I select text using the Mouse, this property is always the same as the LastOffset. If I select text using ctrl-a then this property is what it should be, 0.

Can you duplicate this?
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
The start offset of the selection is only the same as the end offset of the selection if there is no selection range. In that case both offsets are the same as the caret offset. If there is a selection range, the end offset is where the caret is.

I'm pretty sure there's no problems here or else painting would not work correctly.


Actipro Software Support

Posted 14 years ago by John
Avatar
all the same, I'm also pretty sure this is what is happening.

I have a break point into this block...

if (...SelectedView.Selection.Length > 0)
{
SelOffset = pTab.syntaxEdit.SelectedView.Selection.LastOffset;
SelOffset = pTab.syntaxEdit.SelectedView.Selection.StartOffset;
}


both values are identical only with mouse selection. If what you're saying is the case it wouldn't come up.
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
No I said StartOffset and EndOffset will be different when there is a selection. Start offset is where the start anchor is. End offset is where the caret ends up (which could be before the start offset if a backwards selection was made).

Since the start and end offsets could be backwards, we made the FirstOffset and LastOffset properties which return the normalized selection range. So Start- and End- are a pair and First- and Last- are a pair.


Actipro Software Support

Posted 14 years ago by John
Avatar
gotcha, I didn't realize you had 4 offsets... makes sense now since I tend to select going upwards.
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
It's a little confusing but is complete, and by using one pair or the other you can get to all the information you need.


Actipro Software Support

The latest build of this product (v2018.1 build 0341) was released 6 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.