private async void ScriptTextBox_KeyDown(object sender, KeyEventArgs e) { switch (e.Key) { case Key.Enter: e.Handled = true; HistoryText.Document.Blocks.Add(new Paragraph(new Run($"> {ScriptTextBox.Text}"))); _scriptsHistory.Add(ScriptTextBox.Text); _historyIndex = _scriptsHistory.Count; await _scriptHandler.ExecuteCode(ScriptTextBox.Text); ScriptTextBox.Text = string.Empty; ScriptTextBox.Focus(); break; case Key.Up: _historyIndex = Math.Max(0, _historyIndex - 1); if (_scriptsHistory.Count > _historyIndex) { ScriptTextBox.Text = _scriptsHistory[_historyIndex]; ScriptTextBox.CaretIndex = ScriptTextBox.Text.Length; } e.Handled = true; break; case Key.Down: _historyIndex = Math.Min(_scriptsHistory.Count, _historyIndex + 1); if (_scriptsHistory.Count > _historyIndex) { ScriptTextBox.Text = _scriptsHistory[_historyIndex]; ScriptTextBox.CaretIndex = ScriptTextBox.Text.Length; } else { ScriptTextBox.Text = string.Empty; } e.Handled = true; break; } }
private void Window_Loaded(object sender, RoutedEventArgs e) { ScriptTextBox.Focus(); }