I want to add formatting to user input as the user is typing it. I can intercept key press events and apply formatting as the keystrokes are happening, but when I reset the value of the textfield the cursor reverts to the beginning of the string. How can I maintain cursor position and apply formatting?

1 answer

Staff August 20, 2015

Cursor position is controlled by “position” field of a text field component. It provides API that allows you to change cursor location to the given offset, line and column. In your case most likely you need to call “position.setOffset(offset)” method.  To control user input that really changes a value of a text field component you should override two methods:

  • “write(offset, str)”  It is called to write the given string at the given location
  • “remove(offset, len)” It is called to remove the given part of a text field value

Please login or Register to Submit Answer