@@ -1576,12 +1576,46 @@ private void OnEditCommand( string command )
15761576 commandInputFieldAutoCompletedNow = false ;
15771577 }
15781578
1579- // Command input field has lost focus
1580- private void OnEndEditCommand ( string command )
1581- {
1582- if ( commandSuggestionsContainer . gameObject . activeSelf )
1583- commandSuggestionsContainer . gameObject . SetActive ( false ) ;
1584- }
1579+ // Command input field has lost focus
1580+ private void OnEndEditCommand ( string command )
1581+ {
1582+ if ( ! commandSuggestionsContainer . gameObject . activeSelf )
1583+ return ;
1584+
1585+ // Check if any command suggestion is clicked
1586+ #if ENABLE_INPUT_SYSTEM && ! ENABLE_LEGACY_INPUT_MANAGER
1587+ if ( visibleCommandSuggestionInstances > 0 && Pointer . current != null && Pointer . current . press . wasPressedThisFrame )
1588+ #else
1589+ if ( visibleCommandSuggestionInstances > 0 && Input . GetMouseButtonDown ( 0 ) )
1590+ #endif
1591+ {
1592+ #if ENABLE_INPUT_SYSTEM && ! ENABLE_LEGACY_INPUT_MANAGER
1593+ Vector2 pointerPosition = Pointer . current . position . ReadValue ( ) ;
1594+ #else
1595+ Vector2 pointerPosition = Input . mousePosition ;
1596+ #endif
1597+
1598+ Canvas canvas = commandInputField . textComponent . canvas ;
1599+ Camera canvasCamera = ( canvas . renderMode == RenderMode . ScreenSpaceOverlay || ( canvas . renderMode == RenderMode . ScreenSpaceCamera && canvas . worldCamera == null ) ) ? null : ( canvas . worldCamera != null ) ? canvas . worldCamera : Camera . main ;
1600+ if ( RectTransformUtility . RectangleContainsScreenPoint ( commandSuggestionsContainer , pointerPosition , canvasCamera ) && RectTransformUtility . ScreenPointToLocalPointInRectangle ( commandSuggestionsContainer , pointerPosition , canvasCamera , out Vector2 localPoint ) )
1601+ {
1602+ /// <see cref="commandSuggestionInstances"/> have their Pivot Y set to 1 so we need localPoint to have the same pivot value.
1603+ localPoint . y -= commandSuggestionsContainer . rect . height ;
1604+
1605+ for ( int i = 0 ; i < visibleCommandSuggestionInstances ; i ++ )
1606+ {
1607+ if ( localPoint . y >= commandSuggestionInstances [ i ] . rectTransform . anchoredPosition . y - commandSuggestionInstances [ i ] . rectTransform . sizeDelta . y * commandSuggestionInstances [ i ] . rectTransform . pivot . y )
1608+ {
1609+ commandInputField . text = matchingCommandSuggestions [ i ] . command + ( ( matchingCommandSuggestions [ i ] . parameters . Length > 0 ) ? " " : null ) ;
1610+ StartCoroutine ( ActivateCommandInputFieldCoroutine ( ) ) ;
1611+ return ;
1612+ }
1613+ }
1614+ }
1615+ }
1616+
1617+ commandSuggestionsContainer . gameObject . SetActive ( false ) ;
1618+ }
15851619
15861620 // Debug window is being resized,
15871621 // Set the sizeDelta property of the window accordingly while
@@ -1821,17 +1855,22 @@ private void CheckScreenCutout()
18211855#endif
18221856 }
18231857
1824- #if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBGL
1825- private IEnumerator ActivateCommandInputFieldCoroutine ( )
1826- {
1827- // Waiting 1 frame before activating commandInputField ensures that the toggleKey isn't captured by it
1828- yield return null ;
1829- commandInputField . ActivateInputField ( ) ;
1858+ private IEnumerator ActivateCommandInputFieldCoroutine ( )
1859+ {
1860+ yield return null ;
18301861
1831- yield return null ;
1832- commandInputField . MoveTextEnd ( false ) ;
1833- }
1834- #endif
1862+ /// Don't select the text during this automated activation of <see cref="TMP_InputField"/> because it's distracting.
1863+ bool onFocusSelectAll = commandInputField . onFocusSelectAll ;
1864+ commandInputField . onFocusSelectAll = false ;
1865+
1866+ commandInputField . ActivateInputField ( ) ;
1867+
1868+ /// Wait for <see cref="TMP_InputField.LateUpdate"/> because input field's activation is handled there.
1869+ yield return null ;
1870+
1871+ commandInputField . MoveTextEnd ( false ) ;
1872+ commandInputField . onFocusSelectAll = onFocusSelectAll ;
1873+ }
18351874
18361875 // Pool an unused log item
18371876 internal void PoolLogItem ( DebugLogItem logItem )
0 commit comments