mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-15 13:04:36 +00:00
feat: Enhance command input handling by adding support for multi-line text input and refining text change logic
This commit is contained in:
parent
a6c832b744
commit
871bc7651f
1 changed files with 34 additions and 8 deletions
|
|
@ -118,6 +118,7 @@ namespace MinecraftClient.Tui
|
|||
};
|
||||
|
||||
_commandInput.AddHandler(KeyDownEvent, OnCommandKeyDown, Avalonia.Interactivity.RoutingStrategies.Tunnel);
|
||||
_commandInput.AddHandler(TextInputEvent, OnCommandTextInput, Avalonia.Interactivity.RoutingStrategies.Tunnel);
|
||||
_commandInput.TextChanged += OnCommandTextChanged;
|
||||
|
||||
var promptLabel = new TextBlock
|
||||
|
|
@ -487,18 +488,41 @@ namespace MinecraftClient.Tui
|
|||
_commandInput.CaretIndex = pos;
|
||||
}
|
||||
|
||||
private void OnCommandTextInput(object? sender, TextInputEventArgs e)
|
||||
{
|
||||
string? incoming = e.Text;
|
||||
if (string.IsNullOrEmpty(incoming) || (!incoming.Contains('\n') && !incoming.Contains('\r')))
|
||||
return;
|
||||
|
||||
e.Handled = true;
|
||||
|
||||
string[] lines = incoming.Split(["\r\n", "\r", "\n"], StringSplitOptions.None);
|
||||
|
||||
string prefix = _commandInput.Text ?? "";
|
||||
for (int i = 0; i < lines.Length; i++)
|
||||
{
|
||||
string line = lines[i];
|
||||
bool isLast = i == lines.Length - 1;
|
||||
|
||||
if (line.Length > 0 || prefix.Length > 0)
|
||||
{
|
||||
_acceptingSuggestion = true;
|
||||
try { _commandInput.Text = prefix + line; }
|
||||
finally { _acceptingSuggestion = false; }
|
||||
}
|
||||
|
||||
if (!isLast)
|
||||
{
|
||||
SubmitCommand();
|
||||
prefix = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnCommandTextChanged(object? sender, TextChangedEventArgs e)
|
||||
{
|
||||
string text = _commandInput.Text ?? string.Empty;
|
||||
|
||||
if (text.Contains('\n') || text.Contains('\r'))
|
||||
{
|
||||
string cleaned = text.Replace("\r\n", " ").Replace('\r', ' ').Replace('\n', ' ');
|
||||
_commandInput.Text = cleaned;
|
||||
_commandInput.CaretIndex = cleaned.Length;
|
||||
return;
|
||||
}
|
||||
|
||||
if (_acceptingSuggestion || _tabCycling)
|
||||
return;
|
||||
|
||||
|
|
@ -1172,6 +1196,8 @@ namespace MinecraftClient.Tui
|
|||
|
||||
public bool HasOverlay => _overlayContent != null;
|
||||
|
||||
public Control? OverlayContent => _overlayContent;
|
||||
|
||||
protected override void OnKeyDown(KeyEventArgs e)
|
||||
{
|
||||
if (e.Key == Key.Escape && _overlayContent != null)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue