From 86d187eb963931e112512be04cb2a0459885eb41 Mon Sep 17 00:00:00 2001 From: MelekTaus Moribundus Date: Wed, 1 Jul 2026 22:11:28 +0200 Subject: [PATCH] Select pre-filled name in paint save dialog Select the whole pre-filled painting name one frame after activating the input field so the first keystroke replaces it. Done explicitly so it works regardless of the field's authored "On Focus Select All" toggle. Co-Authored-By: Claude Opus 4.8 --- Assets/Scripts/PaintHud.Library.cs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) 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()