protected bool HandlePendingText(InputState state) { string str = textInput?.GetPendingText(); if (string.IsNullOrEmpty(str) || ReadOnly) return false; if (state.Keyboard.ShiftPressed) audio.Sample.Get(@"Keyboard/key-caps")?.Play(); else audio.Sample.Get($@"Keyboard/key-press-{RNG.Next(1, 5)}")?.Play(); insertString(str); return true; }
protected bool HandlePendingText(InputState state) { string str = textInput?.GetPendingText(); if (string.IsNullOrEmpty(str)) { return(false); } if (state.Keyboard.ShiftPressed) { audio.Sample.Get(@"Keyboard/key-caps")?.Play(); } else { audio.Sample.Get($@"Keyboard/key-press-{RNG.Next(1, 5)}")?.Play(); } insertString(str); return(true); }
private bool handleAction(PlatformAction action) { int?amount = null; if (!HandleLeftRightArrows && action.ActionMethod == PlatformActionMethod.Move && (action.ActionType == PlatformActionType.CharNext || action.ActionType == PlatformActionType.CharPrevious)) { return(false); } switch (action.ActionType) { // Clipboard case PlatformActionType.Cut: case PlatformActionType.Copy: if (string.IsNullOrEmpty(SelectedText) || !AllowClipboardExport) { return(true); } clipboard?.SetText(SelectedText); if (action.ActionType == PlatformActionType.Cut) { removeCharacterOrSelection(); } return(true); case PlatformActionType.Paste: //the text may get pasted into the hidden textbox, so we don't need any direct clipboard interaction here. string pending = textInput?.GetPendingText(); if (string.IsNullOrEmpty(pending)) { pending = clipboard?.GetText(); } insertString(pending); return(true); case PlatformActionType.SelectAll: selectionStart = 0; selectionEnd = text.Length; cursorAndLayout.Invalidate(); return(true); // Cursor Manipulation case PlatformActionType.CharNext: amount = 1; break; case PlatformActionType.CharPrevious: amount = -1; break; case PlatformActionType.LineEnd: amount = text.Length; break; case PlatformActionType.LineStart: amount = -text.Length; break; case PlatformActionType.WordNext: if (!AllowWordNavigation) { amount = 1; } else { int searchNext = MathHelper.Clamp(selectionEnd, 0, Text.Length - 1); while (searchNext < Text.Length && text[searchNext] == ' ') { searchNext++; } int nextSpace = text.IndexOf(' ', searchNext); amount = (nextSpace >= 0 ? nextSpace : text.Length) - selectionEnd; } break; case PlatformActionType.WordPrevious: if (!AllowWordNavigation) { amount = -1; } else { int searchPrev = MathHelper.Clamp(selectionEnd - 2, 0, Text.Length - 1); while (searchPrev > 0 && text[searchPrev] == ' ') { searchPrev--; } int lastSpace = text.LastIndexOf(' ', searchPrev); amount = lastSpace > 0 ? -(selectionEnd - lastSpace - 1) : -selectionEnd; } break; } if (amount.HasValue) { switch (action.ActionMethod) { case PlatformActionMethod.Move: resetSelection(); moveSelection(amount.Value, false); break; case PlatformActionMethod.Select: moveSelection(amount.Value, true); break; case PlatformActionMethod.Delete: if (selectionLength == 0) { selectionEnd = MathHelper.Clamp(selectionStart + amount.Value, 0, text.Length); } if (selectionLength > 0) { removeCharacterOrSelection(); } break; } return(true); } return(false); }