public void Issue328() { Assert.True(_map.MapWithNoRemap("<S-SPACE>", "<ESC>", KeyRemapMode.Insert)); var res = _map.GetKeyMapping(KeyInputUtil.ApplyModifiersToChar(' ', KeyModifiers.Shift), KeyRemapMode.Insert); Assert.Equal(KeyInputUtil.EscapeKey, res.Single()); }
public void Issue328() { var left = KeyNotationUtil.StringToKeyInput("<S-SPACE>"); var right = KeyInputUtil.ApplyModifiersToChar(' ', KeyModifiers.Shift); Assert.Equal(left, right); }
/// <summary> /// This maps letters which are pressed to a KeyInput value by looking at the virtual /// key vs the textual input. When Visual Studio is processing key mappings it's doing /// so in PreTraslateMessage and using the virtual key codes. We need to simulate this /// as best as possible when forwarding keys /// </summary> private bool TryConvertLetterToKeyInput(KeyEventArgs keyEventArgs, out KeyInput keyInput) { keyInput = KeyInput.DefaultValue; var keyboardDevice = keyEventArgs.Device as KeyboardDevice; var keyModifiers = keyboardDevice != null ? _keyUtil.GetKeyModifiers(keyboardDevice.Modifiers) : KeyModifiers.Alt; if (keyModifiers == KeyModifiers.None) { return(false); } var key = keyEventArgs.Key; if (key < Key.A || key > Key.Z) { return(false); } var c = (char)('a' + (key - Key.A)); keyInput = KeyInputUtil.ApplyModifiersToChar(c, keyModifiers); return(true); }
static KeyboardInputSimulation() { var combos = new[] { ModifierKeys.None, ModifierKeys.Shift, ModifierKeys.Control, ModifierKeys.Alt, ModifierKeys.Alt | ModifierKeys.Shift }; var map = new Dictionary <KeyInput, KeyData>(); foreach (char c in KeyInputUtilTest.CharLettersLower) { foreach (var mod in combos) { var keyMod = AlternateKeyUtil.ConvertToKeyModifiers(mod); var keyInput = KeyInputUtil.ApplyModifiersToChar(c, keyMod); var key = (Key)((c - 'a') + (int)Key.A); map[keyInput] = new KeyData(key, mod); } } map[KeyInputUtil.CharToKeyInput(' ')] = new KeyData(Key.Space, ModifierKeys.None); map[KeyInputUtil.CharToKeyInput('.')] = new KeyData(Key.OemPeriod, ModifierKeys.None); map[KeyInputUtil.CharToKeyInput(';')] = new KeyData(Key.OemSemicolon, ModifierKeys.None); map[KeyInputUtil.CharToKeyInput(':')] = new KeyData(Key.OemSemicolon, ModifierKeys.Shift); KeyDataMap = map; }
/// <summary> /// This method handles the KeyInput as it applies to command line editor. Make sure to /// mark the key as handled if we use it here. If we don't then it will propagate out to /// the editor and be processed again /// </summary> internal void HandleKeyEvent(KeyEventArgs e) { switch (e.Key) { case Key.Escape: _vimBuffer.Process(KeyInputUtil.EscapeKey); ChangeEditKind(EditKind.None); e.Handled = true; break; case Key.Return: ExecuteCommand(_margin.CommandLineTextBox.Text); e.Handled = true; break; case Key.Up: _vimBuffer.Process(KeyInputUtil.VimKeyToKeyInput(VimKey.Up)); e.Handled = true; break; case Key.Down: _vimBuffer.Process(KeyInputUtil.VimKeyToKeyInput(VimKey.Down)); e.Handled = true; break; case Key.R: if (e.KeyboardDevice.Modifiers == ModifierKeys.Control) { // During edits we are responsible for handling the command line. Need to // put a " into the box at the edit position var textBox = _margin.CommandLineTextBox; var text = textBox.Text; var builder = new StringBuilder(); var offset = textBox.SelectionStart; builder.Append(text, 0, offset); builder.Append('"'); builder.Append(text, offset, text.Length - offset); UpdateCommandLine(builder.ToString()); textBox.Select(offset, 0); // Now move the buffer into paste wait _vimBuffer.Process(KeyInputUtil.ApplyModifiersToChar('r', KeyModifiers.Control)); } break; case Key.U: if (e.KeyboardDevice.Modifiers == ModifierKeys.Control) { var textBox = _margin.CommandLineTextBox; var text = textBox.Text.Substring(textBox.SelectionStart); textBox.Text = text; UpdateVimBufferStateWithCommandText(text); } break; } }
public void KeyMap_ShiftAndTab() { Create("cat", "dog"); _vimBuffer.Process(":map <S-TAB> o<Esc>", enter: true); _simulation.Run(KeyInputUtil.ApplyModifiersToChar('\t', KeyModifiers.Shift)); Assert.Equal(3, _textBuffer.CurrentSnapshot.LineCount); Assert.Equal("cat", _textBuffer.GetLine(0).GetText()); Assert.Equal("", _textBuffer.GetLine(1).GetText()); Assert.Equal("dog", _textBuffer.GetLine(2).GetText()); }
public void WithShiftModifier() { var stroke = new KeyStroke( KeyInputUtil.CharToKeyInput('#'), KeyModifiers.Shift); Assert.Equal(KeyInputUtil.CharToKeyInput('#'), stroke.KeyInput); Assert.Equal(KeyInputUtil.ApplyModifiersToChar('#', KeyModifiers.Shift), stroke.AggregateKeyInput); Assert.Equal('#', stroke.Char); }
public void ControlToAlphaUpper() { var baseCharCode = 0x1; for (var i = 0; i < CharLettersUpper.Length; i++) { var target = (char)(baseCharCode + i); var keyInputUpper = KeyInputUtil.ApplyModifiersToChar(CharLettersUpper[i], KeyModifiers.Control); var keyInputLower = KeyInputUtil.ApplyModifiersToChar(CharLettersLower[i], KeyModifiers.Control); Assert.Equal(keyInputUpper, keyInputLower); } }
static ReportDesignerUtil() { // The set of keys which are special handled are defined by the CodeWindow::ProcessKeyMessage inside // of Microsoft.ReportDesigner.dll SpecialHandledSet.Add(KeyInputUtil.EnterKey); SpecialHandledSet.Add(KeyInputUtil.TabKey); SpecialHandledSet.Add(KeyInputUtil.EscapeKey); SpecialHandledSet.Add(KeyInputUtil.VimKeyToKeyInput(VimKey.Delete)); SpecialHandledSet.Add(KeyInputUtil.VimKeyToKeyInput(VimKey.Back)); SpecialHandledSet.Add(KeyInputUtil.VimKeyToKeyInput(VimKey.PageUp)); SpecialHandledSet.Add(KeyInputUtil.ApplyModifiersToVimKey(VimKey.PageUp, KeyModifiers.Shift)); SpecialHandledSet.Add(KeyInputUtil.VimKeyToKeyInput(VimKey.PageDown)); SpecialHandledSet.Add(KeyInputUtil.ApplyModifiersToVimKey(VimKey.PageDown, KeyModifiers.Shift)); SpecialHandledSet.Add(KeyInputUtil.VimKeyToKeyInput(VimKey.End)); SpecialHandledSet.Add(KeyInputUtil.ApplyModifiersToVimKey(VimKey.End, KeyModifiers.Shift)); SpecialHandledSet.Add(KeyInputUtil.ApplyModifiersToVimKey(VimKey.End, KeyModifiers.Control)); SpecialHandledSet.Add(KeyInputUtil.ApplyModifiersToVimKey(VimKey.End, KeyModifiers.Control | KeyModifiers.Shift)); SpecialHandledSet.Add(KeyInputUtil.VimKeyToKeyInput(VimKey.Home)); SpecialHandledSet.Add(KeyInputUtil.ApplyModifiersToVimKey(VimKey.Home, KeyModifiers.Shift)); SpecialHandledSet.Add(KeyInputUtil.ApplyModifiersToVimKey(VimKey.Home, KeyModifiers.Control)); SpecialHandledSet.Add(KeyInputUtil.ApplyModifiersToVimKey(VimKey.Home, KeyModifiers.Control | KeyModifiers.Shift)); SpecialHandledSet.Add(KeyInputUtil.VimKeyToKeyInput(VimKey.Left)); SpecialHandledSet.Add(KeyInputUtil.ApplyModifiersToVimKey(VimKey.Left, KeyModifiers.Shift)); SpecialHandledSet.Add(KeyInputUtil.ApplyModifiersToVimKey(VimKey.Left, KeyModifiers.Control)); SpecialHandledSet.Add(KeyInputUtil.ApplyModifiersToVimKey(VimKey.Left, KeyModifiers.Control | KeyModifiers.Shift)); SpecialHandledSet.Add(KeyInputUtil.VimKeyToKeyInput(VimKey.Right)); SpecialHandledSet.Add(KeyInputUtil.ApplyModifiersToVimKey(VimKey.Right, KeyModifiers.Shift)); SpecialHandledSet.Add(KeyInputUtil.ApplyModifiersToVimKey(VimKey.Right, KeyModifiers.Control)); SpecialHandledSet.Add(KeyInputUtil.ApplyModifiersToVimKey(VimKey.Right, KeyModifiers.Control | KeyModifiers.Shift)); SpecialHandledSet.Add(KeyInputUtil.VimKeyToKeyInput(VimKey.Up)); SpecialHandledSet.Add(KeyInputUtil.ApplyModifiersToVimKey(VimKey.Up, KeyModifiers.Shift)); SpecialHandledSet.Add(KeyInputUtil.VimKeyToKeyInput(VimKey.Down)); SpecialHandledSet.Add(KeyInputUtil.ApplyModifiersToVimKey(VimKey.Down, KeyModifiers.Shift)); SpecialHandledSet.Add(KeyInputUtil.ApplyModifiersToChar('a', KeyModifiers.Control)); SpecialHandledSet.Add(KeyInputUtil.ApplyModifiersToChar('v', KeyModifiers.Control)); SpecialHandledSet.Add(KeyInputUtil.ApplyModifiersToChar('x', KeyModifiers.Control)); SpecialHandledSet.Add(KeyInputUtil.ApplyModifiersToChar('y', KeyModifiers.Control)); SpecialHandledSet.Add(KeyInputUtil.ApplyModifiersToChar('z', KeyModifiers.Control)); SpecialHandledSet.Add(KeyInputUtil.ApplyModifiersToChar('z', KeyModifiers.Control | KeyModifiers.Shift)); SpecialHandledSet.Add(KeyInputUtil.CharToKeyInput('\b')); }
public void AlphaWithAltIsCaseSensitive() { AssertSingle("<A-b>", KeyInputUtil.ApplyModifiersToChar('b', KeyModifiers.Alt)); AssertSingle("<A-B>", KeyInputUtil.ApplyModifiersToChar('B', KeyModifiers.Alt)); }
public void AlphaWithControl() { AssertSingle("<C-x>", KeyInputUtil.ApplyModifiersToChar('x', KeyModifiers.Control)); AssertSingle("<c-X>", KeyInputUtil.ApplyModifiersToChar('X', KeyModifiers.Control)); }
public void ShiftNumberShouldNotPromote() { AssertSingle("<S-1>", KeyInputUtil.ApplyModifiersToChar('1', KeyModifiers.Shift)); AssertSingle("<s-1>", KeyInputUtil.ApplyModifiersToChar('1', KeyModifiers.Shift)); }
public void ShiftAndControlModifier() { AssertSingle("<C-S-A>", KeyInputUtil.ApplyModifiersToChar('A', KeyModifiers.Control)); }
public void NotationControlAndSymbol() { AssertSingle("<C-]>", KeyInputUtil.ApplyModifiersToChar(']', KeyModifiers.Control)); }