Reading cursor position in textField

Hi!

I’m currently working on an app that requires some text input, for which I use standard native.newTextField().

However, I’d like for user to have a way to quickly input some expressions/symbols that may not be available on system keyboard, therefore I need to read the position of cursor inside the field and insert text accordingly. Something like existing :setSelection() method but for getting selection instead.

Is there a way to do that? Or maybe a reasonable workaround?

Thanks!

Hi @krzanows,

I’m not clear on your need. Do you want to “replace” a certain number of characters in the text input with other characters? Or “insert” several new characters between others?

What method do you plan to use for inserting these expressions? Some type of buttons?

Best regards,

Brent

Hi!

Yes, I’m using buttons to input my expressions.

Currently, I have a button that says “USERNAME”, which inserts “USERNAME” in the text field, on the end of whatever text is there already.

What I’m looking for, is a way to determine where user is currently typing, so when there is some text typed in the field, like “This is a sentence” and user taps the beginning of the sentence (visually cursor moves from last right position to first left), subsequent tap of the button change text in the field to “USERNAMEThis is a sentence”, and not “This is a sentenceUSERNAME”.

Ideally, I would also like to replace characters selected in the text, so when user selects some range of characters, i.e. “This is”, tapping the button changes text in the field to “USERNAME a sentence”.

Thanks!

Hi @krzanows,

I’m not clear on your need. Do you want to “replace” a certain number of characters in the text input with other characters? Or “insert” several new characters between others?

What method do you plan to use for inserting these expressions? Some type of buttons?

Best regards,

Brent

Hi!

Yes, I’m using buttons to input my expressions.

Currently, I have a button that says “USERNAME”, which inserts “USERNAME” in the text field, on the end of whatever text is there already.

What I’m looking for, is a way to determine where user is currently typing, so when there is some text typed in the field, like “This is a sentence” and user taps the beginning of the sentence (visually cursor moves from last right position to first left), subsequent tap of the button change text in the field to “USERNAMEThis is a sentence”, and not “This is a sentenceUSERNAME”.

Ideally, I would also like to replace characters selected in the text, so when user selects some range of characters, i.e. “This is”, tapping the button changes text in the field to “USERNAME a sentence”.

Thanks!