Cursor position in text field

I have a Perspective text field with a text string. I have buttons which allow the user to append select unicode characters (such as up or down arrows) to the end of the string. The buttons simply take the string from the text field / add the character to the end / and stick the new string back in. I would like to add a custom property to the text field that keeps track of the last cursor position when the field had focus so that when they click a button, the character can be added where the cursor was. I see that there is a mouse click position, which is close, but doesn’t really provide a good mathematical way to track the cursor. Especially since it can be altered by mouse clicks as well.

Perspective? If so, I think you are out of luck.

Vision? If so, you can dig under the hood for the text field’s selection controls, where you can monitor and dictate where the cursor is or what fragment of the text is selected.

Just noticed “Perspective” in the first sentence. (Just added?)

There is a topic where another forum member was trying something similar.

While it may be possible, its certainly not going to be easy or clean.

Yes, as stated this is Perspective. If there is no way to expose the cursor position, I have an alternate method I dreamt up. I’m just not sure it is better than having them erase back to where they want the character and then rebuilding the rest of the message.
I have defer updates set to false. I could have them type a special character like ‘~’ where they want something inserted. When that is detected in the string, I could use a popup, or just make a 'character palette visible. When they select the character they want, I could substitute in for the special character, then send focus back to the text field. It just seems even less intuitive than having to erase back to the desired location. I would need to have detailed instructions on the form.

I spent some time playing with this, and made some progress by using a string array tag and a custom property for the position. The left and right arrow keys will update the position property and insert an underscore at he array element corresponding the the position property. Next i used some key event scripts to insert typed characters into the array. I wasnt able to figure out how to capture the backspace event, and it completely ignores where clicked into the text field.

It works, but feels hacky and way too complicated, just deleting back to where you want to start typing is probably the way to go.

Sounds like this is more work than it is worth for my application but I appreciate the insights.

1 Like

Yeah you need js to do this, which means you would need to make your own module, which is a lot of work xd

Depending on what needs to be typed i suppose an other option could be a flexrepeater with a textfield with the lenght of 1 char and every time a char is added it makes a new instance of the field.
Then you can use tab to move to the next. (and shift+tab to move back)
So you should be able to know which instance you are in to add your input inbetween

But i doubt it will be responsive enough… so you would have to be able to handle multiple letters in one textfield and then make it split itself up with a script.

You’ll also have to juggle with auto focus so you dont have to press tab on every key entry