using System.Globalization; namespace Febe.Browser.Gestures; /// /// The closed key map of the profile search (issue #37): the only characters Febe may type into the site's search /// box, each with its full key stroke. Letters a–z, digits, «.», «_» (Shift and Minus, with a real Shift key) and the /// space. There is no path to Enter, Tab or Escape: , which maps a line break to Enter, /// is never used by the search. /// public static class SearchKeyMap { /// The stroke for , or null when the search may not type it. public static KeyStroke? For(char c) { var text = c.ToString(CultureInfo.InvariantCulture); return c switch { >= 'a' and <= 'z' => new KeyStroke(text, "Key" + char.ToUpperInvariant(c).ToString(CultureInfo.InvariantCulture), char.ToUpperInvariant(c), KeyModifiers.None, text), >= '0' and <= '9' => new KeyStroke(text, "Digit" + text, c, KeyModifiers.None, text), '.' => new KeyStroke(".", "Period", 190, KeyModifiers.None, "."), '_' => new KeyStroke("_", "Minus", 189, KeyModifiers.Shift, "_"), ' ' => new KeyStroke(" ", "Space", 32, KeyModifiers.None, " "), _ => null, }; } /// True when every character of is in the map. public static bool CanType(string text) { ArgumentNullException.ThrowIfNull(text); foreach (var c in text) { if (For(c) is null) { return false; } } return true; } /// Backspace: the only key the search uses to erase. public static KeyStroke Backspace { get; } = Keyboard.Special(SpecialKey.Backspace); /// End: the only key the search uses to move the caret. public static KeyStroke End { get; } = Keyboard.Special(SpecialKey.End); }