Skip to content

Commit b122d5b

Browse files
committed
ToggleKey now closes the window if its the first character entered in the input field.
1 parent 9f0db7b commit b122d5b

File tree

2 files changed

+20
-29
lines changed

2 files changed

+20
-29
lines changed

Resources/Prefabs/FAB_DevConsole.Instance.prefab

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -998,19 +998,7 @@ MonoBehaviour:
998998
m_Calls: []
999999
m_OnValueChanged:
10001000
m_PersistentCalls:
1001-
m_Calls:
1002-
- m_Target: {fileID: 3982050654428888601}
1003-
m_TargetAssemblyTypeName: DavidFDev.DebugConsoleMono, Unity.DavidFDev.DebugConsole
1004-
m_MethodName: OnInputValueChanged
1005-
m_Mode: 1
1006-
m_Arguments:
1007-
m_ObjectArgument: {fileID: 0}
1008-
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
1009-
m_IntArgument: 0
1010-
m_FloatArgument: 0
1011-
m_StringArgument:
1012-
m_BoolArgument: 0
1013-
m_CallState: 2
1001+
m_Calls: []
10141002
m_CaretColor: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1}
10151003
m_CustomCaretColor: 1
10161004
m_SelectionColor: {r: 0.65882355, g: 0.80784315, b: 1, a: 0.7529412}

Runtime/DevConsoleMono.cs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)