Skip to content

Commit c84be0c

Browse files
committed
Added support for CTRL+Backspace in the input field.
1 parent ce35cf1 commit c84be0c

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## [Unreleased]
88
- Added real-time parameter information when typing out a command.
99
- Added built-in support for null and default values for parameters.
10+
- Added support for CTRL + Backspace in the input field.
1011
- Added commands for executing C# expressions or statements at runtime.
1112
- Added exception handling for command callbacks.
1213
- Added a reminder in the devconsole command that the console is disabled by default in release builds.

Runtime/DevConsoleMono.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ internal sealed class DevConsoleMono : MonoBehaviour
6666
#endif
6767
private const InputKey UpArrowKey = InputKey.UpArrow;
6868
private const InputKey DownArrowKey = InputKey.DownArrow;
69+
private const InputKey BackspaceKey = InputKey.Backspace;
70+
private const InputKey LeftControlKey =
71+
#if USE_NEW_INPUT_SYSTEM
72+
InputKey.LeftCtrl;
73+
#else
74+
InputKey.LeftControl;
75+
#endif
6976
private const string InputSystemPrefabPath = "Prefabs/" +
7077
#if USE_NEW_INPUT_SYSTEM
7178
"FAB_DevConsole.NewEventSystem";
@@ -137,6 +144,7 @@ internal sealed class DevConsoleMono : MonoBehaviour
137144
private bool _focusInputField = false;
138145
private bool _oldFocusInputField = false;
139146
private Dictionary<InputKey, string> _bindings = new Dictionary<InputKey, string>();
147+
private bool _ignoreCtrlBackspace = false;
140148

141149
#endregion
142150

@@ -613,6 +621,24 @@ internal void LogCommand(string name)
613621

614622
internal void OnInputValueChanged(string _)
615623
{
624+
// Check if CTRL + Backspace was pressed, and remove a word before the caret position
625+
if (!_ignoreCtrlBackspace && GetKey(LeftControlKey) && GetKeyDown(BackspaceKey))
626+
{
627+
string tilCaret = InputText.Substring(0, InputCaretPosition);
628+
string afterCaret = InputText.Substring(InputCaretPosition, InputText.Length - InputCaretPosition);
629+
string[] split = tilCaret.Split(' ');
630+
int length = 0;
631+
for (int i = 0; i < split.Length - 1; ++i)
632+
{
633+
length += split[i].Length + 1;
634+
}
635+
636+
_ignoreCtrlBackspace = true;
637+
InputText = InputText.Substring(0, length) + afterCaret;
638+
_ignoreCtrlBackspace = false;
639+
InputCaretPosition = length;
640+
}
641+
616642
RefreshCommandSuggestions();
617643
RefreshCommandParameterSuggestions();
618644
}
@@ -2641,6 +2667,21 @@ private bool GetKeyDown(InputKey key)
26412667
#endif
26422668
}
26432669

2670+
/// <summary>
2671+
/// Check if the specified key is pressed, using the correct input system.
2672+
/// </summary>
2673+
/// <param name="key"></param>
2674+
/// <returns></returns>
2675+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2676+
private bool GetKey(InputKey key)
2677+
{
2678+
#if USE_NEW_INPUT_SYSTEM
2679+
return Keyboard.current[key].isPressed;
2680+
#else
2681+
return Input.GetKey(key);
2682+
#endif
2683+
}
2684+
26442685
/// <summary>
26452686
/// Get the current mouse position, using the correct input system.
26462687
/// </summary>

0 commit comments

Comments
 (0)