public void ReceiveCommandInput(char command) { if (Text == null) { Text = ""; } // Prevent alt gr from triggering any of these as that combination is often needed for special characters if (PlayerInput.IsAltDown()) { return; } switch (command) { case '\b' when !Readonly: //backspace if (PlayerInput.KeyDown(Keys.LeftControl) || PlayerInput.KeyDown(Keys.RightControl)) { SetText(string.Empty, false); CaretIndex = Text.Length; } else if (selectedCharacters > 0) { RemoveSelectedText(); } else if (Text.Length > 0 && CaretIndex > 0) { CaretIndex--; SetText(Text.Remove(CaretIndex, 1)); CalculateCaretPos(); ClearSelection(); } OnTextChanged?.Invoke(this, Text); break; case (char)0x3: // ctrl-c CopySelectedText(); break; case (char)0x16 when !Readonly: // ctrl-v string text = GetCopiedText(); RemoveSelectedText(); if (SetText(Text.Insert(CaretIndex, text))) { CaretIndex = Math.Min(Text.Length, CaretIndex + text.Length); OnTextChanged?.Invoke(this, Text); } break; case (char)0x18: // ctrl-x CopySelectedText(); if (!Readonly) { RemoveSelectedText(); } break; case (char)0x1: // ctrl-a if (PlayerInput.IsCtrlDown()) { SelectAll(); } break; case (char)0x1A when !Readonly && !SubEditorScreen.IsSubEditor(): // ctrl-z text = memento.Undo(); if (text != Text) { ClearSelection(); SetText(text, false); CaretIndex = Text.Length; OnTextChanged?.Invoke(this, Text); } break; case (char)0x12 when !Readonly && !SubEditorScreen.IsSubEditor(): // ctrl-r text = memento.Redo(); if (text != Text) { ClearSelection(); SetText(text, false); CaretIndex = Text.Length; OnTextChanged?.Invoke(this, Text); } break; } }