How to get Niftygui TextField cursor position

I see

TextFieldControl.setCursorPosition(int);

but I don’t see .getCursorPosition() for some reason. The closest thing I found was TextFieldLogic, which wasn’t publicly exposed. I tried this

    TextFieldControl input = GetChatInput_old(); //gets the textfield of an instance of the chatbox control
    String old_text = input.getText(); //starting text
    TextFieldLogic logic = new TextFieldLogic(old_text, new ClipboardAWT(), input); //can't figure out how to extract, so making a new one
    logic.put(); // I saw someone doing this, so I tried it.
    System.out.println(        
                        logic.getSelectionStart()+" | " + 
                        logic.getSelectionLength()+" | " + 
                        logic.getSelectionEnd()+" | "+ 
                        logic.getCursorPosition() + " | "+
                       logic.getDisplayedText().toString()
                        );

This outputs -1 | 0 | -1 | {integer representing the length of the current contents of the clipboard} | {the contents of the clipboard followed by the contents of the textfield}

If I remove the logic.put(); line, it’s always -1 | 0 | -1 | 0 | {current contents of the textfield}

The eventual goal (in addition to manipulating the cursor) is a textbox with emoticon substitution like :fire_element: being replaced with :fire: in the chat box. When the :fire: is copied and pasted out of textbox, it should be pasted as the string :fire_element: again. I’d rather not recreate the redraw function and all the clicking and highlighting functions.

I notice TextFieldControl is deprecated, but I didn’t see an alternative and it’s used in the included ChatControl. Considering my goals, what’s the best way to do this?

I haven’t used Nifty in a long time, but I think I used an alternative. I’m not sure what it was (I’ll look it up for you later), but it was something like NiftyTextFieldControl. I’m not 100% sure though.

I’d appreciate it if you did. I googled “niftytextfieldcontrol” (in quotes) and came up with nothing

I looked through the source and it seems I’m partially mistaken.
All controls (like textfields) must implement NiftyControl. TextField extends NiftyControl, and TextFieldControl implements TextField. I thought it was deprecated because of a rewrite, but it seems that it is only deprecated to encourage you to use TextField itself (you should follow that advice).

However, about your actual question:
It indeed seems that TextField.getCursorPosition is missing. I’m not sure why that is, but you could easily hack it in (just need to put a getter in TextField and override that in TextFieldLogic).

By the way, i strongly recommend to not instantiate thing like TextFieldLogic yourself, as that can mess with Nifty.