|
| 1 | +open Oni_Model; |
| 2 | +open Oni_IntegrationTestLib; |
| 3 | +open EditorCoreTypes; |
| 4 | + |
| 5 | +runTest(~name="InputRemapMotionTest (#2114)", (dispatch, wait, runEffects) => { |
| 6 | + wait(~name="Initial mode is normal", (state: State.t) => |
| 7 | + Selectors.mode(state) |> Vim.Mode.isNormal |
| 8 | + ); |
| 9 | + |
| 10 | + let testFile = getAssetPath("some-test-file.txt"); |
| 11 | + // Open an erroneous CSS file - verify we get some diagnostics |
| 12 | + dispatch(Actions.OpenFileByPath(testFile, None, None)); |
| 13 | + |
| 14 | + wait(~name="buffer load", (state: State.t) => { |
| 15 | + switch (Selectors.getActiveBuffer(state)) { |
| 16 | + | Some(buffer) => Oni_Core.Buffer.getNumberOfLines(buffer) > 2 |
| 17 | + | None => false |
| 18 | + } |
| 19 | + }); |
| 20 | + |
| 21 | + // #2114 - remap hjkl -> jklm |
| 22 | + dispatch( |
| 23 | + VimExecuteCommand({allowAnimation: true, command: "nnoremap j h "}), |
| 24 | + ); |
| 25 | + runEffects(); |
| 26 | + |
| 27 | + dispatch( |
| 28 | + VimExecuteCommand({allowAnimation: true, command: "nnoremap l k "}), |
| 29 | + ); |
| 30 | + runEffects(); |
| 31 | + |
| 32 | + dispatch( |
| 33 | + VimExecuteCommand({allowAnimation: true, command: "nnoremap m l "}), |
| 34 | + ); |
| 35 | + runEffects(); |
| 36 | + |
| 37 | + dispatch( |
| 38 | + VimExecuteCommand({allowAnimation: true, command: "nnoremap k j "}), |
| 39 | + ); |
| 40 | + runEffects(); |
| 41 | + |
| 42 | + let input = key => { |
| 43 | + let modifiers = EditorInput.Modifiers.none; |
| 44 | + |
| 45 | + let keyPress: EditorInput.KeyPress.t = |
| 46 | + EditorInput.KeyPress.physicalKey( |
| 47 | + ~key=EditorInput.Key.Character(key), |
| 48 | + ~modifiers, |
| 49 | + ); |
| 50 | + let time = Revery.Time.now(); |
| 51 | + |
| 52 | + dispatch(Model.Actions.KeyDown({key: keyPress, scancode: 1, time})); |
| 53 | + dispatch(Model.Actions.KeyUp({key: keyPress, scancode: 1, time})); |
| 54 | + runEffects(); |
| 55 | + }; |
| 56 | + |
| 57 | + let waitForCursorPosition = bytePosition => { |
| 58 | + wait( |
| 59 | + ~name="Verify cursor is at:" ++ BytePosition.show(bytePosition), |
| 60 | + (state: State.t) => { |
| 61 | + let cursorPosition = |
| 62 | + state.layout |
| 63 | + |> Feature_Layout.activeEditor |
| 64 | + |> Feature_Editor.Editor.getPrimaryCursorByte; |
| 65 | + |
| 66 | + cursorPosition == bytePosition; |
| 67 | + }, |
| 68 | + ); |
| 69 | + }; |
| 70 | + |
| 71 | + waitForCursorPosition( |
| 72 | + BytePosition.{line: LineNumber.zero, byte: ByteIndex.zero}, |
| 73 | + ); |
| 74 | + |
| 75 | + // Move down, jklm style |
| 76 | + input('k'); |
| 77 | + waitForCursorPosition( |
| 78 | + BytePosition.{line: LineNumber.(zero + 1), byte: ByteIndex.zero}, |
| 79 | + ); |
| 80 | + |
| 81 | + // Move right, jklm style |
| 82 | + input('m'); |
| 83 | + waitForCursorPosition( |
| 84 | + BytePosition.{line: LineNumber.(zero + 1), byte: ByteIndex.(zero + 1)}, |
| 85 | + ); |
| 86 | + |
| 87 | + // Move up, jklm style |
| 88 | + input('l'); |
| 89 | + waitForCursorPosition( |
| 90 | + BytePosition.{line: LineNumber.(zero), byte: ByteIndex.(zero + 1)}, |
| 91 | + ); |
| 92 | + |
| 93 | + // Move left, jklm style |
| 94 | + input('j'); |
| 95 | + waitForCursorPosition( |
| 96 | + BytePosition.{line: LineNumber.(zero), byte: ByteIndex.(zero)}, |
| 97 | + ); |
| 98 | +}); |
0 commit comments