I need to know the value of selStart when i click into a textArea: at present, if I do not click twice, the position of the insertion point following the mouseDown, does not match selStart.
For instance, with the following snippet inside the mouseDown event handler of a textArea:
label1.text = str(me.selStart)
Clicking at the 10th character of the text, label1 may show 300 or any other wrong number; clicking again at the same position, I get the right selStart-value.
I do not know if this problem affects also win32.
Any suggestion how to fix the problem?
post the exact code (including the event name)… I’ve done this exact thing many times with no issues that I recall
If I remember right, the new Selstart is set only when MouseUp occurs.
In a new project, add one label and one textArea.
Function MouseDown(X As Integer, Y As Integer) As Boolean
Label1.text = str(me.SelStart)
Type: “I go to London”
Clicking between “o” and “n” of London, label1 shows 14
Click again at the same position, label1 shows 10
Click anywhere else, label1 shows 10; click again at it shows the real value of selStart.
And so on and so forth: that is, the first click shows the last value of selSart. Only at the second click I get the value of the insertion point.
@Michel Bujardet Not in my tests, either returning FALSE or nothing in the mouseDown event.
This has nothing to do with implementing MouseUp. Xojo gets the cursor position in MouseUp. That is why you never get the present value in MouseDown.
Use a timer mode Off 500 ms period, that you start in MouseDown, to get the SelStart value.
In my app I have several textAreas and when I used the timer approach I had to subclass a timer in order for the timer to understand which textArea was the one with focus.
But if mouseDown has to be ruled out, then I agree that the timer approach may be the best solution. In fact, SelChange too returns the right selStart value, but it creates other problems, for instance, right-clicking in the textArea, the full word will get selected.
You could use Xojo.Core.Timer CallLater to pass a reference of the TextArea to the timer.
Thank you, Michel; I’ve never used it, but I’ll give a try.
Meantime I found that, in the mouseDown event,
label1.text = str(me.CharPosAtXY(x,y)) works fine for my purpose.