Getting InsertionPosition from SelectionStart

I’d like to find the insertionPosition, which requires x,y . I don’t have a mouseClick, pnly the lsst character in the TestArea, which be where the caret is, which would be SelectionStart.
I looked up a post but it seems longer than necessary.
https://forum.xojo.com/t/how-to-localize-insertion-point-to-x-y/26971
I’m bsffled by how to get it.
How do I get it?

so you need the x,y from cursor position?
and what if the content is scrolled or cursor is out of view?
you will overlay the textarea at x,y then?
at windows it is possible to change the small vertical cursor with other symbol in mouse settings.

I am looking for the InsertionPoint so I can paste text, which is the next step

Use SelectionStart to set the position of the insertion point in the text.

if the user click into text or move the cursor i guess this start change.
i think the “insert point” is where the cursor is.
if the cursor is at the end and you paste something it will be append or not?

the insert point is automatic set by user, or calculated via method and x,y or by a offset value.

The cursor is already there. I put it by doing control end.
I need to know how to find it from text.SelectionStart. or just the end of the text in a TextArea.

I don’t understand. If you want to paste text, don’t you just set SelectedText?

What I’m doing is, while pasting text (in the On Paste homegrown event) I’m also setting the font size. I know that I can append the text if I have selectionLength I can set that fontsize without redoing the whole TextArea. What I cannot get is the insertionPosition to make sure the point is at the end of all of the text.

You can set the insertion point with SelectionStart.

TextArea1.SelectionStart = TextArea1.Text.Length
TextArea1.SelectedText = "abcd"
TextArea1.SelectionFontSize = 16

I understand, but I cannot tell where SelectionStart is. I cannot tell if it is in the middle or at the end.

I’m sorry, I must not be understanding your intent. If you want to add text to the end of the textarea, then it doesn’t matter where the insertion point is. You just set it yourself.

Can you elaborate on what you’re trying to accomplish?

If TextArea1.SelectionStart < TextArea1.Text.Length Then
   // Insertion point is in the middle
Else
   // Insertion point is at then end
End If

I am trying to make sure it is the end.
I am trying to APPEND text not just set it. But, in order to append, it must be at the end of the text.
Sometimes, programmatically it is easier to just redo with Style Runs the whole thing. I am trying to circumvent it.

That’s what the code I posted does.

Sorry, I didn’t read fully the second post’s code.
My apologies

My apologies. I was looking for insertion point with the x,y
I’m guessing there isn’t a way of getting there without a mouse click
BTW The code works.

I’m guessing there isn’t a way of getting there without a mouse click
how you will get there? by method, by keyboard, by mouse? all possible.

by method
TextArea1.SelectionStart =
TextArea1.SelectionLength =

by mouse it is automatic if the control is enabled.
but you could do in the mouse down event return true and in the mouse up event

TextArea1.SelectionStart = TextArea1.InsertionPosition(X,Y)
TextArea1.SelectionLength = 3

by keyboard u use cursor for the position and shift+cursor for the selection.

if you use this in a button click the selection will colored and bigger.

TextArea1.SelectionFontSize = 16
TextArea1.SelectionTextColor = Color.Red
Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.