-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(keybindings): execute keybinding starting with : as ex command (#…
…2397) A simple change that allows keybindings to invoke ex commands directly, and could address quite a few of the requests in #1423. The downside of doing this instead of implementing proper commands is of course that they won't be discoverable through the command palette, but this doesn't prevent proper commands to be added either, so I think it might be a nice convenient stop-gap solution to unblock people at least. Example: ``` {key: "kk", command: ":split", when: "editorTextFocus"} ``` Let me know if you think this is a viable approach @bryphe, then I'll add a few integration tests before it's merged. Fixes #807
- Loading branch information
Showing
4 changed files
with
133 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters