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 <noreply@anthropic.com>
This commit is contained in:
1 parent
5c36ddc9e6
commit
86d187eb96
1 file changed
+18
-3
@@ -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()
|
||||
|
||||
Reference in new issue
Block a user