/// <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) : VimKeyModifiers.Alt; if (keyModifiers == VimKeyModifiers.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.ApplyKeyModifiersToChar(c, keyModifiers); return(true); }
public void Issue328() { Assert.True(_map.AddKeyMapping("<S-SPACE>", "<ESC>", allowRemap: false, KeyRemapMode.Insert)); var res = _map.Map(KeyInputUtil.ApplyKeyModifiersToChar(' ', VimKeyModifiers.Shift), KeyRemapMode.Insert).AsMapped().KeyInputSet.KeyInputs.Single(); Assert.Equal(KeyInputUtil.EscapeKey, res); }
static KeyboardInputSimulation() { var combos = new[] { ModifierKeys.None, ModifierKeys.Shift, ModifierKeys.Control, ModifierKeys.Alt, ModifierKeys.Alt | ModifierKeys.Shift }; var map = new Dictionary <KeyInput, KeyData>(); foreach (var c in KeyInputUtil.CharLettersLower) { foreach (var mod in combos) { var keyMod = AlternateKeyUtil.ConvertToKeyModifiers(mod); var keyInput = KeyInputUtil.ApplyKeyModifiersToChar(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); s_keyDataMap = map; }
public void Issue328() { var left = KeyNotationUtil.StringToKeyInput("<S-SPACE>"); var right = KeyInputUtil.ApplyKeyModifiersToChar(' ', VimKeyModifiers.Shift); Assert.Equal(left, right); }
public void Issue328() { Assert.True(_map.MapWithNoRemap("<S-SPACE>", "<ESC>", KeyRemapMode.Insert)); var res = _map.GetKeyMapping(KeyInputUtil.ApplyKeyModifiersToChar(' ', VimKeyModifiers.Shift), KeyRemapMode.Insert); Assert.Equal(KeyInputUtil.EscapeKey, res.Single()); }
/// <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); ExecuteCommand(_commandText); 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.ApplyKeyModifiersToChar('r', VimKeyModifiers.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; } }
private void CancelPasteWait() { Debug.Assert(InPasteWait); // Cancel the paste-wait state in the buffer // TODO: see if there is a better way to do this _vimBuffer.Process(KeyInputUtil.ApplyKeyModifiersToChar(RegisterName.Blackhole.Char.Value, VimKeyModifiers.Control)); EndPasteWait(); }
public void ShiftAndTab() { Create("cat", "dog"); _vimBuffer.Process(":map <S-TAB> o<Esc>", enter: true); _vsSimulation.Run(KeyInputUtil.ApplyKeyModifiersToChar('\t', VimKeyModifiers.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 AlphaLowerAndAltGr() { // Vim don't let you map Alt-Gr combinations (Ctrl + Alt), intead it should see just the plain character // The #1008 and #1390 issues were caused by VsVim not handling those combinations properly. foreach (var c in KeyInputUtilTest.CharLettersLower) { var keyInput = KeyInputUtil.ApplyKeyModifiersToChar(c, VimKeyModifiers.Alt | VimKeyModifiers.Control); Assert.Equal(c.ToString(), KeyNotationUtil.GetDisplayName(keyInput)); } }
public void WithShiftModifier() { var stroke = new KeyStroke( KeyInputUtil.CharToKeyInput('#'), VimKeyModifiers.Shift); Assert.Equal(KeyInputUtil.CharToKeyInput('#'), stroke.KeyInput); Assert.Equal(KeyInputUtil.ApplyKeyModifiersToChar('#', VimKeyModifiers.Shift), stroke.AggregateKeyInput); Assert.Equal('#', stroke.Char); }
private bool GetKeyInputFromKey(NSEvent theEvent, NSEventModifierMask modifierKeys, out KeyInput keyInput) { if (!string.IsNullOrEmpty(theEvent.CharactersIgnoringModifiers)) { var keyModifiers = ConvertToKeyModifiers(modifierKeys); keyInput = KeyInputUtil.ApplyKeyModifiersToChar(theEvent.CharactersIgnoringModifiers[0], keyModifiers); return(true); } keyInput = null; return(false); }
private bool GetKeyInputFromKey(Key key, ModifierKeys modifierKeys, out KeyInput keyInput) { if (GetCharFromKey(key, modifierKeys, out char unicodeChar)) { var keyModifiers = ConvertToKeyModifiers(modifierKeys); keyInput = KeyInputUtil.ApplyKeyModifiersToChar(unicodeChar, keyModifiers); return(true); } keyInput = null; return(false); }
public void ControlToAlphaUpper() { var baseCharCode = 0x1; for (var i = 0; i < CharLettersUpper.Length; i++) { var target = (char)(baseCharCode + i); var keyInputUpper = KeyInputUtil.ApplyKeyModifiersToChar(CharLettersUpper[i], VimKeyModifiers.Control); var keyInputLower = KeyInputUtil.ApplyKeyModifiersToChar(CharLettersLower[i], VimKeyModifiers.Control); Assert.Equal(keyInputUpper, keyInputLower); } }
private void HandleKeyEventInPasteWait(KeyEventArgs e) { Debug.Assert(InPasteWait); switch (e.Key) { case Key.R: if (e.KeyboardDevice.Modifiers == ModifierKeys.Control) { e.Handled = true; // remain in paste-wait state } break; case Key.A: if (e.KeyboardDevice.Modifiers == ModifierKeys.Control) { e.Handled = HandlePasteSpecial(KeyInputUtil.ApplyKeyModifiersToChar('a', VimKeyModifiers.Control), WordKind.BigWord); } break; case Key.W: if (e.KeyboardDevice.Modifiers == ModifierKeys.Control) { e.Handled = HandlePasteSpecial(KeyInputUtil.ApplyKeyModifiersToChar('w', VimKeyModifiers.Control), WordKind.NormalWord); } break; case Key.J: case Key.M: if (e.KeyboardDevice.Modifiers == ModifierKeys.Control) { CancelPasteWait(); e.Handled = true; } break; case Key.Escape: case Key.Enter: case Key.Left: case Key.Right: case Key.Back: case Key.Delete: CancelPasteWait(); e.Handled = true; break; } }
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.ApplyKeyModifiersToKey(VimKey.PageUp, VimKeyModifiers.Shift)); SpecialHandledSet.Add(KeyInputUtil.VimKeyToKeyInput(VimKey.PageDown)); SpecialHandledSet.Add(KeyInputUtil.ApplyKeyModifiersToKey(VimKey.PageDown, VimKeyModifiers.Shift)); SpecialHandledSet.Add(KeyInputUtil.VimKeyToKeyInput(VimKey.End)); SpecialHandledSet.Add(KeyInputUtil.ApplyKeyModifiersToKey(VimKey.End, VimKeyModifiers.Shift)); SpecialHandledSet.Add(KeyInputUtil.ApplyKeyModifiersToKey(VimKey.End, VimKeyModifiers.Control)); SpecialHandledSet.Add(KeyInputUtil.ApplyKeyModifiersToKey(VimKey.End, VimKeyModifiers.Control | VimKeyModifiers.Shift)); SpecialHandledSet.Add(KeyInputUtil.VimKeyToKeyInput(VimKey.Home)); SpecialHandledSet.Add(KeyInputUtil.ApplyKeyModifiersToKey(VimKey.Home, VimKeyModifiers.Shift)); SpecialHandledSet.Add(KeyInputUtil.ApplyKeyModifiersToKey(VimKey.Home, VimKeyModifiers.Control)); SpecialHandledSet.Add(KeyInputUtil.ApplyKeyModifiersToKey(VimKey.Home, VimKeyModifiers.Control | VimKeyModifiers.Shift)); SpecialHandledSet.Add(KeyInputUtil.VimKeyToKeyInput(VimKey.Left)); SpecialHandledSet.Add(KeyInputUtil.ApplyKeyModifiersToKey(VimKey.Left, VimKeyModifiers.Shift)); SpecialHandledSet.Add(KeyInputUtil.ApplyKeyModifiersToKey(VimKey.Left, VimKeyModifiers.Control)); SpecialHandledSet.Add(KeyInputUtil.ApplyKeyModifiersToKey(VimKey.Left, VimKeyModifiers.Control | VimKeyModifiers.Shift)); SpecialHandledSet.Add(KeyInputUtil.VimKeyToKeyInput(VimKey.Right)); SpecialHandledSet.Add(KeyInputUtil.ApplyKeyModifiersToKey(VimKey.Right, VimKeyModifiers.Shift)); SpecialHandledSet.Add(KeyInputUtil.ApplyKeyModifiersToKey(VimKey.Right, VimKeyModifiers.Control)); SpecialHandledSet.Add(KeyInputUtil.ApplyKeyModifiersToKey(VimKey.Right, VimKeyModifiers.Control | VimKeyModifiers.Shift)); SpecialHandledSet.Add(KeyInputUtil.VimKeyToKeyInput(VimKey.Up)); SpecialHandledSet.Add(KeyInputUtil.ApplyKeyModifiersToKey(VimKey.Up, VimKeyModifiers.Shift)); SpecialHandledSet.Add(KeyInputUtil.VimKeyToKeyInput(VimKey.Down)); SpecialHandledSet.Add(KeyInputUtil.ApplyKeyModifiersToKey(VimKey.Down, VimKeyModifiers.Shift)); SpecialHandledSet.Add(KeyInputUtil.ApplyKeyModifiersToChar('a', VimKeyModifiers.Control)); SpecialHandledSet.Add(KeyInputUtil.ApplyKeyModifiersToChar('v', VimKeyModifiers.Control)); SpecialHandledSet.Add(KeyInputUtil.ApplyKeyModifiersToChar('x', VimKeyModifiers.Control)); SpecialHandledSet.Add(KeyInputUtil.ApplyKeyModifiersToChar('y', VimKeyModifiers.Control)); SpecialHandledSet.Add(KeyInputUtil.ApplyKeyModifiersToChar('z', VimKeyModifiers.Control)); SpecialHandledSet.Add(KeyInputUtil.ApplyKeyModifiersToChar('z', VimKeyModifiers.Control | VimKeyModifiers.Shift)); SpecialHandledSet.Add(KeyInputUtil.CharToKeyInput('\b')); }
/// <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.J: case Key.M: if (e.KeyboardDevice.Modifiers == ModifierKeys.Control) { ExecuteCommand(_margin.CommandLineTextBox.Text); e.Handled = true; } break; case Key.Up: e.Handled = HandleHistoryNavigation(KeyInputUtil.VimKeyToKeyInput(VimKey.Up)); break; case Key.Down: e.Handled = HandleHistoryNavigation(KeyInputUtil.VimKeyToKeyInput(VimKey.Down)); break; case Key.Home: if ((e.KeyboardDevice.Modifiers & ModifierKeys.Shift) == 0) { _margin.UpdateCaretPosition(EditPosition.Start); e.Handled = true; } break; case Key.End: if ((e.KeyboardDevice.Modifiers & ModifierKeys.Shift) == 0) { _margin.UpdateCaretPosition(EditPosition.End); e.Handled = true; } break; case Key.Left: // Ignore left arrow if at start position e.Handled = _margin.IsCaretAtStart(); break; case Key.Back: // Backspacing past the beginning aborts the command/search. if (_margin.CommandLineTextBox.Text.Length <= 1) { _vimBuffer.Process(KeyInputUtil.EscapeKey); ChangeEditKind(EditKind.None); e.Handled = true; } break; case Key.Tab: InsertIntoCommandLine("\t", putCaretAfter: true); var commandText = _margin.CommandLineTextBox.Text; UpdateVimBufferStateWithCommandText(commandText); 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 InsertIntoCommandLine("\"", putCaretAfter: false); // Now move the buffer into paste wait _vimBuffer.Process(KeyInputUtil.ApplyKeyModifiersToChar('r', VimKeyModifiers.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; case Key.P: if (e.KeyboardDevice.Modifiers == ModifierKeys.Control) { e.Handled = HandleHistoryNavigation(KeyInputUtil.ApplyKeyModifiersToChar('p', VimKeyModifiers.Control)); } break; case Key.N: if (e.KeyboardDevice.Modifiers == ModifierKeys.Control) { e.Handled = HandleHistoryNavigation(KeyInputUtil.ApplyKeyModifiersToChar('n', VimKeyModifiers.Control)); } break; } }
public void AlphaWithAltIsCaseSensitive() { AssertSingle("<A-b>", KeyInputUtil.ApplyKeyModifiersToChar('b', VimKeyModifiers.Alt)); AssertSingle("<A-B>", KeyInputUtil.ApplyKeyModifiersToChar('B', VimKeyModifiers.Alt)); }
public void AlphaWithControl() { AssertSingle("<C-x>", KeyInputUtil.ApplyKeyModifiersToChar('x', VimKeyModifiers.Control)); AssertSingle("<c-X>", KeyInputUtil.ApplyKeyModifiersToChar('X', VimKeyModifiers.Control)); }
public void ShiftNumberShouldNotPromote() { AssertSingle("<S-1>", KeyInputUtil.ApplyKeyModifiersToChar('1', VimKeyModifiers.Shift)); AssertSingle("<s-1>", KeyInputUtil.ApplyKeyModifiersToChar('1', VimKeyModifiers.Shift)); }
public void ShiftAndControlModifier() { AssertSingle("<C-S-A>", KeyInputUtil.ApplyKeyModifiersToChar('A', VimKeyModifiers.Control)); }
public void NotationControlAndSymbol() { AssertSingle("<C-]>", KeyInputUtil.ApplyKeyModifiersToChar(']', VimKeyModifiers.Control)); }
/// <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) { if (InPasteWait) { HandleKeyEventInPasteWait(e); return; } switch (e.Key) { case Key.Escape: _vimBuffer.Process(KeyInputUtil.EscapeKey); ChangeEditKind(EditKind.None); e.Handled = true; break; case Key.C: if (e.KeyboardDevice.Modifiers == ModifierKeys.Control) { if (_margin.CommandLineTextBox.SelectionLength != 0) { // Copy if there is a selection. // Reported in issue #2338. _clipboardDevice.Text = _margin.CommandLineTextBox.SelectedText; } else { _vimBuffer.Process(KeyInputUtil.EscapeKey); ChangeEditKind(EditKind.None); } e.Handled = true; } break; case Key.Return: ExecuteCommand(_margin.CommandLineTextBox.Text); e.Handled = true; break; case Key.J: case Key.M: if (e.KeyboardDevice.Modifiers == ModifierKeys.Control) { ExecuteCommand(_margin.CommandLineTextBox.Text); e.Handled = true; } break; case Key.Up: e.Handled = HandleHistoryNavigation(KeyInputUtil.VimKeyToKeyInput(VimKey.Up)); break; case Key.Down: e.Handled = HandleHistoryNavigation(KeyInputUtil.VimKeyToKeyInput(VimKey.Down)); break; case Key.Home: if ((e.KeyboardDevice.Modifiers & ModifierKeys.Shift) == 0) { _margin.UpdateCaretPosition(EditPosition.Start); e.Handled = true; } break; case Key.End: if ((e.KeyboardDevice.Modifiers & ModifierKeys.Shift) == 0) { _margin.UpdateCaretPosition(EditPosition.End); e.Handled = true; } break; case Key.Left: // Ignore left arrow if at start position e.Handled = _margin.IsCaretAtStart(); break; case Key.Back: // Backspacing past the beginning aborts the command/search. if (_margin.CommandLineTextBox.Text.Length <= 1) { _vimBuffer.Process(KeyInputUtil.EscapeKey); ChangeEditKind(EditKind.None); e.Handled = true; } else if (_margin.CommandLineTextBox.CaretIndex == 1) { // don't let the caret get behind the initial character e.Handled = true; } break; case Key.Tab: InsertIntoCommandLine("\t", putCaretAfter: true); var commandText = _margin.CommandLineTextBox.Text; UpdateVimBufferStateWithCommandText(commandText); 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 _pasteWaitMemo.Set(_margin.CommandLineTextBox); InsertIntoCommandLine("\"", putCaretAfter: false); // Now move the buffer into paste wait _vimBuffer.Process(KeyInputUtil.ApplyKeyModifiersToChar('r', VimKeyModifiers.Control)); e.Handled = true; } break; case Key.U: if (e.KeyboardDevice.Modifiers == ModifierKeys.Control) { var textBox = _margin.CommandLineTextBox; if (textBox.SelectionStart > 1) { var text = textBox.Text.Substring(textBox.SelectionStart); textBox.Text = text; UpdateVimBufferStateWithCommandText(text); textBox.Select(1, 0); } e.Handled = true; } break; case Key.W: if (e.KeyboardDevice.Modifiers == ModifierKeys.Control) { DeleteWordBeforeCursor(); e.Handled = true; } break; case Key.P: if (e.KeyboardDevice.Modifiers == ModifierKeys.Control) { e.Handled = HandleHistoryNavigation(KeyInputUtil.ApplyKeyModifiersToChar('p', VimKeyModifiers.Control)); } break; case Key.N: if (e.KeyboardDevice.Modifiers == ModifierKeys.Control) { e.Handled = HandleHistoryNavigation(KeyInputUtil.ApplyKeyModifiersToChar('n', VimKeyModifiers.Control)); } break; case Key.D6: if (e.KeyboardDevice.Modifiers == ModifierKeys.Control) { ToggleLanguage(); e.Handled = true; } break; } }
/// <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: e.Handled = HandleHistoryNavigation(KeyInputUtil.VimKeyToKeyInput(VimKey.Up)); break; case Key.Down: e.Handled = HandleHistoryNavigation(KeyInputUtil.VimKeyToKeyInput(VimKey.Up)); break; case Key.Home: if ((e.KeyboardDevice.Modifiers & ModifierKeys.Shift) == 0) { _margin.UpdateCaretPosition(EditPosition.Start); e.Handled = true; } break; case Key.End: if ((e.KeyboardDevice.Modifiers & ModifierKeys.Shift) == 0) { _margin.UpdateCaretPosition(EditPosition.End); e.Handled = true; } break; case Key.Left: case Key.Back: // Ignore backspace if at start position e.Handled = _margin.IsCaretAtStart(); 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.ApplyKeyModifiersToChar('r', VimKeyModifiers.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; } }