Could it be that the CharacterPosition(x,y) method in DesktopTextArea has an error?
If I include the following statements in the DesktopTextArea in the MouseDown event:
if IsContextualClick then
var mouseAtCharPos as integer = me.CharacterPosition(x,y)
var textLength as integer = me.Text.Length
end if
then I always get the same result for the mouseAtCharPos and the textLength, although the XY position was at a different position in the text at each attempt.
I have tested this in macOS 14.4 with XOJO 2023R4.
Works fine here - also macOS 14.4 and Xojo 2023R4.
Textlength is always the same, as you ask for the length of the complete contents of the DesktopTextArea.
mouseAtCharPos is different every time when I right click at a different place in the DesktopTextArea.
I have built a new project and added my extensions piece by piece. I did a test after each installation.
Now I have found the cause: It was the ruler.
I had it in the opening event of the TextArea.
Declare sub setRulerVisible lib "Cocoa" selector "setRulerVisible:" (obj_id as Ptr, value as Boolean)
setRulerVisible(ptr(documentView(me.Handle)), showRuler)
Now the Ruler is deactivated and CharacterPosition works again.
Since I can’t turn off the error, I’ll do without the Ruler.
Declare sub setRulerVisible lib "Cocoa" selector "setRulerVisible:" (obj_id as Ptr, value as Boolean)
setRulerVisible(ptr(documentView(me.Handle)), true)
These two lines display a ruler in the TextArea.
For the ruler to be visible, there must be a “true” at the end of the second line.
Because the ruler is shown in the TextArea, the TextArea.CharacterPosition will probably no longer work.
Can’t you remove the Rule height to the y value and use that to compute the position ?
What you wrote makes sense since the function returns the y value from the top of the Control (in fact, the top writing part of the Control area).
Adding something there (in the Control’s Back) produce pertubation.
You may want to know (or remember) that CharacterPosition and related methods are broken, even without using the ruler at all. It’s been several years like that and, well, it’s not reliable.
I didn’t know that there were already issues for this problem. Since I don’t see a solution to the problem, I’ll look at the issues. Then I’ll make an upvote or a new issue.
But I can’t do that until after Easter.