Search Issue Tracker
Won't Fix
Won't Fix in 2023.1.X
Votes
0
Found in
2022.1.23f1
2022.2.0b16
2023.1.0a21
Issue ID
UUM-20731
Regression
No
TextField cursorIndex / selectionIndex are not set in time for Focus/Mouse events
Summary:
I have a TextField txtf with txtf.selectAllOnFocus = txtf.selectAllOnMouseUp = false.
When the user clicks into the text field, I want to know the cursor and selection indices, but I only get the previous indicies, not the ones after the click.
Also refer to this slack discussion.]
Extra Notes:
Try something like this and observe the indices in the test output. Same is true for FocusEvent or MouseUpEvent.
{code:java}
var txtf = new TextField() { value = "Hello World!" };
txtf.selectAllOnFocus = txtf.selectAllOnMouseUp = false;
txtf.RegisterCallback<MouseDownEvent>(UpdateMenu);
void UpdateMenu(EventBase evt)
{
if (evt.target is not TextField txtf) return;
Debug.Log($"MouseDown on TextField: {txtf.cursorIndex}, {txtf.selectIndex}");
} {code}
I have no idea if this is a regression or not!
Expected Results:
I would expect some event that allow me to read to new indices based on the users click position.
Actual Results:
I only get the previous indices, i.e. the first one is always (0, 0), subsequent clicks yield the cursor position from before the click.
Tested on:
Unity Version 2021.1.4f1, Operating System WIN10.
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Required SpriteMask class (ID 331) is stripped when "Strip Engine Code" is enabled
- “Maximized serialized file backup not found” error is thrown when minimizing a window in a newly opened project
- Build stack trace contains invalid lines when building with IL2CPP using scripts with delegates containing generic types in the signature
- Entities Systems window has a “Show Full Player Loop” dropdown which does nothing when clicked after enabling “Show Full Player Loop”
- Entities Hierarchy Search “Show/Hide” button’s Lens Icon is blurry when the Editor is on an external monitor
Resolution Note:
An important refactor to the Event system landed in 2023.2, which fixes the issue.
In previous versions, the trickle-down and bubble-up phases are executed before the ExecuteDefaultActionAtTarget. The workaround for these versions would be to wait for one frame before accessing the selection indices.
Resolution Note (2023.1.X):
An important refactor to the Event system landed in 2023.2, which fixes the issue.
In previous versions, the trickle-down and bubble-up phases are executed before the ExecuteDefaultActionAtTarget. The workaround for these versions would be to wait for one frame before accessing the selection indices.