Skip to content

Commit

Permalink
Merge pull request #2438 from ricksladkey/shift-notation
Browse files Browse the repository at this point in the history
Normalize modifiers in the right hand side of key mappings
  • Loading branch information
ricksladkey committed Dec 6, 2018
2 parents 85c5b2e + 4722716 commit fe52844
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Src/VimCore/KeyInput.fs
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,13 @@ module KeyInputUtil =
| _ -> VimKeyModifiers.None
ApplyKeyModifiers keyInput modifiers

let NormalizeKeyModifiers (keyInput: KeyInput) =
match keyInput.RawChar with
| Some c ->
ApplyKeyModifiersToChar c keyInput.KeyModifiers
| None ->
ApplyKeyModifiersToKey keyInput.Key keyInput.KeyModifiers

let CharWithControlToKeyInput ch =
let keyInput = ch |> CharToKeyInput
ApplyKeyModifiers keyInput VimKeyModifiers.Control
Expand Down
3 changes: 3 additions & 0 deletions Src/VimCore/KeyInput.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ module KeyInputUtil =
/// Apply a click count to the given key input
val ApplyClickCount: keyInput: KeyInput -> clickCount: int -> KeyInput

/// Normalize key modifiers, e.g. removing an irrelevant shift
val NormalizeKeyModifiers: keyInput: KeyInput -> KeyInput

/// Try and convert the given char to a KeyInput value
val CharToKeyInput: c: char -> KeyInput

Expand Down
7 changes: 7 additions & 0 deletions Src/VimCore/KeyMap.fs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,13 @@ type internal KeyMap
let rhs = KeyNotationUtil.TryStringToKeyInputSet rhs
match key, rhs with
| Some left, Some right ->
// Empirically with vim/gvim, <S-$> on the left is never
// matched, but <S-$> on the right is treated as '$'. Reported
// in issue #2313.
let right =
right.KeyInputs
|> Seq.map KeyInputUtil.NormalizeKeyModifiers
|> KeyInputSetUtil.OfSeq
let keyMapping = {
Left = left
Right = right
Expand Down
13 changes: 13 additions & 0 deletions Test/VimCoreTest/NormalModeIntegrationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2792,6 +2792,19 @@ public void Issue1435()
Assert.Equal(" cat", _textBuffer.GetLine(0).GetText());
Assert.Equal("dog", _textBuffer.GetLine(1).GetText());
}

/// <summary>
/// Key modifiers in the right hand side of mappings are normalized
/// </summary>
[WpfFact]
public void NormalizedRightHandSide()
{
// Reported in issue #2313.
Create("cat", "dog", "");
_vimBuffer.Process(":map nn <S-$>", enter: true);
_vimBuffer.Process("nn");
Assert.Equal(2, _textView.GetCaretPoint().Position);
}
}
}

Expand Down

0 comments on commit fe52844

Please sign in to comment.