Search Issue Tracker
Won't Fix
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|[https://unity.slack.com/archives/C3414V4UV/p1670245096185499].]
*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
- “[Worker0] Could not generate preview image“ error when opening macOS native plugin in the Inspector with Architecture to build for set to ARM 64-bit
- [iOS] Application.absoluteURL is empty on Awake/Start when opening via deep link with Splash Screen disabled
- Crash on MemoryManager::Deallocate when rapidly calling Addressables.LoadAssetAsync
- Crash on physx::shdfnd::atomicIncrement when adjusting values on a character controller component after entering Play mode in Prefab edit mode
- [Rendering Debugger] [NewInputSystem] Debug Overlays in Play mode throws InvalidOperationException when using New Input System
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.