x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Editable text: how to get the current caret position?

Hi,

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.

Thank you.

Product Version: UE 4.18
Tags:
more ▼

asked Jan 25 '18 at 01:03 PM in C++ Programming

avatar image

SomeRandomDev
23 2 4 8

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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):

 ETextLocation CaretLocation = StaticCastSharedRef<SEditableTextBox>(TextBox->TakeWidget())->EditableText->EditableTextLayout->CursorInfo.GetCursorInteractionLocation();

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):

 static ETextLocation GetCaretLocationForTextBox(UEditableTextBox& TextBox)
 {
 
 return StaticCastSharedRef<SEditableTextBox>(TextBox.TakeWidget())->GetEditableText()->GetEditableTextLayout()->GetCursorInfo().GetCursorInteractionLocation();
 }

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.

more ▼

answered Jan 25 '18 at 04:29 PM

avatar image

SomeRandomDev
23 2 4 8

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question