From 22af406c2a5763a44a4c3744b523a89f8fa47018 Mon Sep 17 00:00:00 2001 From: glennsl Date: Thu, 3 Sep 2020 14:05:53 +0200 Subject: [PATCH 1/3] execute keybinding starting with : as ex command --- src/Store/KeyBindingsStoreConnector.re | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/Store/KeyBindingsStoreConnector.re b/src/Store/KeyBindingsStoreConnector.re index fa5a360bd6..aef041b39a 100644 --- a/src/Store/KeyBindingsStoreConnector.re +++ b/src/Store/KeyBindingsStoreConnector.re @@ -539,6 +539,11 @@ let start = maybeKeyBindingsFilePath => { } ); + let executeExCommandEffect = command => + Isolinear.Effect.create(~name="keybindings.executeExCommand", () => + ignore(Vim.command(command): Vim.Context.t) + ); + let updater = (state: State.t, action: Actions.t) => { switch (action) { | Actions.Init => (state, loadKeyBindingsEffect(true)) @@ -552,14 +557,21 @@ let start = maybeKeyBindingsFilePath => { ) | KeybindingInvoked({command}) => - switch (Command.Lookup.get(command, State.commands(state))) { - | Some((command: Command.t(_))) => ( + if (command |> Utility.StringEx.startsWith(~prefix=":")) { + ( state, - executeCommandEffect(command.msg), - ) - | None => - Log.errorf(m => m("Unknown command: %s", command)); - (state, Isolinear.Effect.none); + executeExCommandEffect(Base.String.drop_prefix(command, 1)), + ); + } else { + switch (Command.Lookup.get(command, State.commands(state))) { + | Some((command: Command.t(_))) => ( + state, + executeCommandEffect(command.msg), + ) + | None => + Log.errorf(m => m("Unknown command: %s", command)); + (state, Isolinear.Effect.none); + }; } | _ => (state, Isolinear.Effect.none) From f569877b1f176c5804d5fced42e60cddbd0d4b6c Mon Sep 17 00:00:00 2001 From: glennsl Date: Fri, 4 Sep 2020 13:43:46 +0200 Subject: [PATCH 2/3] add integration test --- integration_test/ExCommandKeybindingTest.re | 49 +++++++++++++++++++++ integration_test/dune | 2 + 2 files changed, 51 insertions(+) create mode 100644 integration_test/ExCommandKeybindingTest.re diff --git a/integration_test/ExCommandKeybindingTest.re b/integration_test/ExCommandKeybindingTest.re new file mode 100644 index 0000000000..794cf33f95 --- /dev/null +++ b/integration_test/ExCommandKeybindingTest.re @@ -0,0 +1,49 @@ +open Oni_Model; +open Oni_IntegrationTestLib; +open Actions; + +let keybindings = + Some( + {| +[ + {"key": "kk", "command": ":split", "when": "editorTextFocus"} +] +|}, + ); + +runTest( + ~keybindings, + ~name="ExCommandKeybindingTest", + (dispatch, wait, _) => { + let input = key => { + let keyPress = + EditorInput.KeyPress.{ + scancode: Sdl2.Scancode.ofName(key), + keycode: Sdl2.Keycode.ofName(key), + modifiers: EditorInput.Modifiers.none, + }; + let time = Revery.Time.now(); + + dispatch(KeyDown(keyPress, time)); + //dispatch(TextInput(key)); + dispatch(KeyUp(keyPress, time)); + }; + + wait(~name="Initial sanity check", (state: State.t) => { + let splitCount = + state.layout |> Feature_Layout.visibleEditors |> List.length; + + splitCount == 1; + }); + + input("k"); + input("k"); + + wait(~name="Wait for split to be created", (state: State.t) => { + let splitCount = + state.layout |> Feature_Layout.visibleEditors |> List.length; + + splitCount == 2; + }); + }, +); diff --git a/integration_test/dune b/integration_test/dune index 11c122535f..8910b80942 100644 --- a/integration_test/dune +++ b/integration_test/dune @@ -12,6 +12,7 @@ EditorFontFromPathTest EditorFontValidTest EditorUtf8Test + ExCommandKeybindingTest ExtConfigurationChangedTest ExtHostBufferOpenTest ExtHostBufferUpdatesTest @@ -77,6 +78,7 @@ EditorFontFromPathTest.exe EditorFontValidTest.exe EditorUtf8Test.exe + ExCommandKeybindingTest.exe ExtConfigurationChangedTest.exe ExtHostBufferOpenTest.exe ExtHostBufferUpdatesTest.exe From f93017a18c8e48a8219d270d711340808d9faece Mon Sep 17 00:00:00 2001 From: glennsl Date: Fri, 4 Sep 2020 14:44:20 +0200 Subject: [PATCH 3/3] add integration test for command with args --- .../ExCommandKeybindingWithArgsTest.re | 61 +++++++++++++++++++ integration_test/dune | 2 + 2 files changed, 63 insertions(+) create mode 100644 integration_test/ExCommandKeybindingWithArgsTest.re diff --git a/integration_test/ExCommandKeybindingWithArgsTest.re b/integration_test/ExCommandKeybindingWithArgsTest.re new file mode 100644 index 0000000000..7313a296e8 --- /dev/null +++ b/integration_test/ExCommandKeybindingWithArgsTest.re @@ -0,0 +1,61 @@ +open Oni_Core; +open Oni_Model; +open Oni_IntegrationTestLib; +open Actions; + +let keybindings = + Some( + {| +[ + {"key": "kk", "command": ":d 2", "when": "editorTextFocus"} +] +|}, + ); + +runTest( + ~keybindings, + ~name="ExCommandKeybindingTest", + (dispatch, wait, _) => { + let input = key => { + let keyPress = + EditorInput.KeyPress.{ + scancode: Sdl2.Scancode.ofName(key), + keycode: Sdl2.Keycode.ofName(key), + modifiers: EditorInput.Modifiers.none, + }; + let time = Revery.Time.now(); + + dispatch(KeyDown(keyPress, time)); + //dispatch(TextInput(key)); + dispatch(KeyUp(keyPress, time)); + }; + + let testFile = getAssetPath("some-test-file.txt"); + dispatch(Actions.OpenFileByPath(testFile, None, None)); + + wait(~name="Verify buffer is loaded", (state: State.t) => + switch (Selectors.getActiveBuffer(state)) { + | Some(buffer) => + Buffer.getShortFriendlyName(buffer) == Some("some-test-file.txt") + | None => false + } + ); + + wait(~name="Verify initial line count", (state: State.t) => + switch (Selectors.getActiveBuffer(state)) { + | Some(buffer) => Buffer.getNumberOfLines(buffer) == 3 + | None => false + } + ); + + input("k"); + input("k"); + + wait(~name="Wait for split to be created", (state: State.t) => + switch (Selectors.getActiveBuffer(state)) { + | Some(buffer) => Buffer.getNumberOfLines(buffer) == 1 + | None => false + } + ); + }, +); diff --git a/integration_test/dune b/integration_test/dune index 8910b80942..a52fc2123c 100644 --- a/integration_test/dune +++ b/integration_test/dune @@ -13,6 +13,7 @@ EditorFontValidTest EditorUtf8Test ExCommandKeybindingTest + ExCommandKeybindingWithArgsTest ExtConfigurationChangedTest ExtHostBufferOpenTest ExtHostBufferUpdatesTest @@ -79,6 +80,7 @@ EditorFontValidTest.exe EditorUtf8Test.exe ExCommandKeybindingTest.exe + ExCommandKeybindingWithArgsTest.exe ExtConfigurationChangedTest.exe ExtHostBufferOpenTest.exe ExtHostBufferUpdatesTest.exe