diff --git a/Assets/Scripts/PaintHud.Library.cs b/Assets/Scripts/PaintHud.Library.cs index 90f6dd5..e7ad7e9 100644 --- a/Assets/Scripts/PaintHud.Library.cs +++ b/Assets/Scripts/PaintHud.Library.cs @@ -188,14 +188,29 @@ public partial class PaintHud { if (!painter || !_saveDialog) return; // Pre-fill the currently selected painting's name so "Save" defaults to overwriting it (empty when - // nothing is selected). The field is focused below; TMP's focus-select then highlights it so the - // first keystroke replaces it for a fresh name. + // nothing is selected) and select that text so the first keystroke replaces it for a fresh name. if (_nameInput) _nameInput.text = _selectedPainting ?? ""; if (_saveInfo) _saveInfo.text = ""; _saveDialog.SetActive(true); _saveDialog.transform.SetAsLastSibling(); // a dragged panel may have moved itself in front; stay on top ValidateSaveName(); - if (_nameInput) _nameInput.ActivateInputField(); + if (_nameInput) + { + _nameInput.ActivateInputField(); + StartCoroutine(SelectNameFieldNextFrame()); + } + } + + // ActivateInputField only takes focus on a later update and resets the caret, so selecting the text this + // frame would be cleared. Wait one frame, then select the whole pre-filled name - done explicitly here so + // it works regardless of the field's authored "On Focus Select All" toggle. + private System.Collections.IEnumerator SelectNameFieldNextFrame() + { + yield return null; + if (!_nameInput) yield break; + _nameInput.selectionStringAnchorPosition = _nameInput.text.Length; + _nameInput.selectionStringFocusPosition = 0; + _nameInput.ForceLabelUpdate(); } private void ValidateSaveName()