Editable text: how to get the current caret position?
Do you know whether threre is any reasonable way of getting the current caret position when positioned in an Editable Text? I mean, which character is it next to. It would be fine if there's a way to do it that works for either the UEditableText (UMG) or the SEditableText (Slate), since the first one contains the second one. I've checked the code of both Editable Text and Editable Text Box classes and they seem to delegate the task of moving the caret position to the Layout, which on its turn delegates it depeer and depeer (the mentioned classes do not hold any variable about the current text position). That's why it seems difficult to find a way to get the caret position.
This question has been asked a couple of times before in the recent years by other people with no response. If it's not currently possible to do this, think of this as a feature request to make it available in future versions of the engine if you think it's interesting enough.
asked Jan 25 '18 at 01:03 PM in C++ Programming
It seems that there would be an actual way to do this in one line (with a UEditableTextBox* TextBox, and similarly for a UEditableText* Text):
But that won't compile, since SEditableTextBox::EditableText, SEditableText::EditableTextLayout and SlateEditableTextLayout::CursorInfo are not public members, but private/protected without getter functions.
Epic, would you find it reasonable to add public getters for these values in a future update?
With the getter functions, it would be something like this (imagine that we are in a library C++ file, that you would expose to Blueprints if needed):
I think many people would find it useful, specially those working in virtual keyboards that need to work with editable text fields in code.
The workaround would be to subclass the three affected classes to add the needed getters and a UEditableTextBox subclass and manually set up the linking of the UMG text box widget with the Slate text box widget with the Slate text widget to get things working, which seems likely to lead to unexpected behavior or incompatibilities when the engine is updated and the parent classes get modified.
Follow this question
Once you sign in you will be able to subscribe for any updates here