@@ -171,7 +171,6 @@ internal sealed class DevConsoleMono : MonoBehaviour
171171 private bool _displayUnityWarnings = true ;
172172 private string [ ] _commandSuggestions = null ;
173173 private int _commandSuggestionIndex = 0 ;
174- private bool _ignoreInputChange = false ;
175174 private readonly List < Type > _cacheEnumTypes = new List < Type > ( MaxCachedEnumTypes ) ;
176175
177176 #endregion
@@ -283,7 +282,6 @@ internal void OpenConsole()
283282 _canvasGroup . blocksRaycasts = true ;
284283 ConsoleIsShowing = true ;
285284 _focusInputField = true ;
286- InputText = InputText . TrimEnd ( '`' ) ;
287285
288286 DevConsole . InvokeOnConsoleOpened ( ) ;
289287 }
@@ -526,31 +524,34 @@ internal void LogCommand(string name)
526524
527525 #region Unity events
528526
529- internal void OnInputValueChanged ( )
527+ internal void OnInputValueChanged ( string _ )
530528 {
531- if ( _ignoreInputChange )
532- {
533- return ;
534- }
529+ RefreshCommandSuggestions ( ) ;
530+ }
535531
536- _ignoreInputChange = true ;
532+ internal char OnValidateInput ( string input , int charIndex , char addedChar )
533+ {
534+ const char EmptyChar = '\0 ' ;
537535
538- // Submit the input if a new line is entered (ENTER)
539- if ( InputText . Contains ( "\n " ) )
536+ if ( addedChar == '\n ' )
540537 {
541- InputText = InputText . Replace ( " \n " , string . Empty ) ;
538+ addedChar = EmptyChar ;
542539 SubmitInput ( ) ;
543540 }
544541
545- // Try autocomplete if tab is entered (TAB)
546- else if ( InputText . Contains ( "\t " ) )
542+ else if ( addedChar == '\t ' )
547543 {
548- InputText = InputText . Replace ( " \t " , string . Empty ) ;
544+ addedChar = EmptyChar ;
549545 AutoComplete ( ) ;
550546 }
551547
548+ else if ( InputText . Length == 0 && ConsoleToggleKey . HasValue && GetKeyDown ( ConsoleToggleKey . Value ) )
549+ {
550+ addedChar = EmptyChar ;
551+ }
552+
552553 RefreshCommandSuggestions ( ) ;
553- _ignoreInputChange = false ;
554+ return addedChar ;
554555 }
555556
556557 internal void OnRepositionButtonPointerDown ( BaseEventData eventData )
@@ -620,6 +621,8 @@ private void Awake()
620621 _currentLogFieldWidth = _initLogFieldWidth ;
621622 _resizeButtonColour = _resizeButtonImage . color ;
622623 _logFieldPrefab . SetActive ( false ) ;
624+ _inputField . onValueChanged . AddListener ( x => OnInputValueChanged ( x ) ) ;
625+ _inputField . onValidateInput += OnValidateInput ;
623626
624627 LoadPreferences ( ) ;
625628 InitBuiltInCommands ( ) ;
@@ -762,7 +765,7 @@ private void LateUpdate()
762765 }
763766
764767 // Check if the developer console toggle key was pressed
765- if ( ConsoleToggleKey . HasValue && ( ! ConsoleIsShowing || ! _inputField . isFocused ) && GetKeyDown ( ConsoleToggleKey . Value ) )
768+ if ( ConsoleToggleKey . HasValue && ( ! ConsoleIsShowing || ( ! _inputField . isFocused || InputText . Length <= 1 ) ) && GetKeyDown ( ConsoleToggleKey . Value ) )
766769 {
767770 ToggleConsole ( ) ;
768771 return ;
0 commit comments