Skip to content

Commit a55e692

Browse files
authoredJan 1, 2021
fix(input/#2883): Handle alternate input productions (#2902)
Fixes #2883 __TODO:__ - [x] Make use of our new keyboard layout module (thanks @zbaylin !) - [x] Bring back special-key handling - [x] Add test case for #2883 - [x] Fix scancodes / verify 'AllKeysReleased' behavior for Control+Tab - [x] Fix bug with C-C / C-D / C-U being forwarded to Vim - [x] Fix newly introduced bug with Control+Shift+P/Cmd+Shift+P __Next steps:__ - #2114 - respect 'no recursive' flag for remaps (#2908) - #2293 - Update the `keyDown` function in `EditorInput` to take a list of candidates as opposed to a single keypress. - #2293 - Enable some bindings that were previously blocked: - `<C-W>+` - `<C-W>_` - `<C-W>|` - Refactor input event subscription and `Sld2.TextInput.start` out of store and into a `Service_Input` sub - Move `input` utility to common integration test infrastructure - Remove the `KeyboardInput` Action
1 parent 19eaed7 commit a55e692

31 files changed

+937
-616
lines changed
 

‎CHANGES_CURRENT.md

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
- #2895 - Completion: Fix crash on long (>1024 character) completion matches (fixes #2892)
2626
- #2905 - CLI: HealthCheck - Re-enable output logging
2727
- #2907 - Editor: Add configuration for document highlights and use proper theme color
28+
- #2902 - Input: Fix remaps for characters w/o scancode (fixes #2883)
2829

2930
### Performance
3031

‎integration_test/ExCommandKeybindingNormTest.re

+4-5
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@ runTest(
1616
let input = key => {
1717
let keyPress =
1818
EditorInput.KeyPress.physicalKey(
19-
~scancode=Sdl2.Scancode.ofName(key),
20-
~keycode=Sdl2.Keycode.ofName(key),
19+
~key,
2120
~modifiers=EditorInput.Modifiers.none,
2221
);
2322
let time = Revery.Time.now();
2423

25-
dispatch(KeyDown(keyPress, time));
24+
dispatch(KeyDown({key: keyPress, scancode: 1, time}));
2625
//dispatch(TextInput(key));
27-
dispatch(KeyUp(keyPress, time));
26+
dispatch(KeyUp({key: keyPress, scancode: 1, time}));
2827
};
2928

3029
let testFile = getAssetPath("some-test-file.txt");
@@ -49,7 +48,7 @@ runTest(
4948
});
5049

5150
// Press k, which is re-bound to 'norm! j'
52-
input("k");
51+
input(EditorInput.Key.Character('k'));
5352

5453
// Verify cursor is at top of file
5554
wait(~name="Verify cursor moved down a line", (state: State.t) => {

‎integration_test/ExCommandKeybindingTest.re

+5-6
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@ runTest(
1818
let input = key => {
1919
let keyPress =
2020
EditorInput.KeyPress.physicalKey(
21-
~scancode=Sdl2.Scancode.ofName(key),
22-
~keycode=Sdl2.Keycode.ofName(key),
21+
~key,
2322
~modifiers=EditorInput.Modifiers.none,
2423
);
2524
let time = Revery.Time.now();
2625

27-
dispatch(KeyDown(keyPress, time));
26+
dispatch(KeyDown({key: keyPress, scancode: 1, time}));
2827
//dispatch(TextInput(key));
29-
dispatch(KeyUp(keyPress, time));
28+
dispatch(KeyUp({key: keyPress, scancode: 1, time}));
3029
};
3130

3231
wait(~name="Initial sanity check", (state: State.t) => {
@@ -36,8 +35,8 @@ runTest(
3635
splitCount == 1;
3736
});
3837

39-
input("k");
40-
input("k");
38+
input(EditorInput.Key.Character('k'));
39+
input(EditorInput.Key.Character('k'));
4140

4241
wait(~name="Wait for split to be created", (state: State.t) => {
4342
let splitCount =

‎integration_test/ExCommandKeybindingWithArgsTest.re

+5-6
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@ runTest(
1919
let input = key => {
2020
let keyPress =
2121
EditorInput.KeyPress.physicalKey(
22-
~scancode=Sdl2.Scancode.ofName(key),
23-
~keycode=Sdl2.Keycode.ofName(key),
22+
~key=EditorInput.Key.Character(key),
2423
~modifiers=EditorInput.Modifiers.none,
2524
);
2625
let time = Revery.Time.now();
2726

28-
dispatch(KeyDown(keyPress, time));
27+
dispatch(KeyDown({key: keyPress, scancode: 1, time}));
2928
//dispatch(TextInput(key));
30-
dispatch(KeyUp(keyPress, time));
29+
dispatch(KeyUp({key: keyPress, scancode: 1, time}));
3130
};
3231

3332
let testFile = getAssetPath("some-test-file.txt");
@@ -48,8 +47,8 @@ runTest(
4847
}
4948
);
5049

51-
input("k");
52-
input("k");
50+
input('k');
51+
input('k');
5352

5453
wait(~name="Wait for split to be created", (state: State.t) =>
5554
switch (Selectors.getActiveBuffer(state)) {

‎integration_test/KeySequenceJJTest.re

+11-10
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,29 @@ runTest(
1717
);
1818

1919
let input = key => {
20-
let scancode = Sdl2.Scancode.ofName(key);
21-
let keycode = Sdl2.Keycode.ofName(key);
2220
let modifiers = EditorInput.Modifiers.none;
2321

2422
let keyPress: EditorInput.KeyPress.t =
25-
EditorInput.KeyPress.physicalKey(~keycode, ~scancode, ~modifiers);
23+
EditorInput.KeyPress.physicalKey(
24+
~key=EditorInput.Key.Character(key),
25+
~modifiers,
26+
);
2627
let time = Revery.Time.now();
2728

28-
dispatch(Model.Actions.KeyDown(keyPress, time));
29+
dispatch(Model.Actions.KeyDown({key: keyPress, scancode: 1, time}));
2930
//dispatch(Model.Actions.TextInput(key));
30-
dispatch(Model.Actions.KeyUp(keyPress, time));
31+
dispatch(Model.Actions.KeyUp({key: keyPress, scancode: 1, time}));
3132
runEffects();
3233
};
3334

34-
input("i");
35+
input('i');
3536
wait(~name="Mode is now insert", (state: State.t) =>
3637
Selectors.mode(state) |> Vim.Mode.isInsert
3738
);
3839

39-
input("a");
40-
input("j");
41-
input("j");
40+
input('a');
41+
input('j');
42+
input('j');
4243

4344
wait(~name="Mode is back to normal", (state: State.t) =>
4445
Selectors.mode(state) |> Vim.Mode.isNormal
@@ -64,7 +65,7 @@ runTest(
6465

6566
// #2601 - Make sure we're _actually_ in normal mode!
6667
// Type another 'j' to see...
67-
input("j");
68+
input('j');
6869

6970
wait(
7071
~name=

‎integration_test/VimScriptLocalFunctionTest.re

+7-6
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,21 @@ runTest(~name="VimScriptLocalFunctionTest", (dispatch, wait, runEffects) => {
2626
runEffects();
2727

2828
let input = key => {
29-
let scancode = Sdl2.Scancode.ofName(key);
30-
let keycode = Sdl2.Keycode.ofName(key);
3129
let modifiers = EditorInput.Modifiers.none;
3230

3331
let keyPress: EditorInput.KeyPress.t =
34-
EditorInput.KeyPress.physicalKey(~scancode, ~keycode, ~modifiers);
32+
EditorInput.KeyPress.physicalKey(
33+
~key=EditorInput.Key.Character(key),
34+
~modifiers,
35+
);
3536
let time = Revery.Time.now();
3637

37-
dispatch(Model.Actions.KeyDown(keyPress, time));
38-
dispatch(Model.Actions.KeyUp(keyPress, time));
38+
dispatch(Model.Actions.KeyDown({key: keyPress, scancode: 1, time}));
39+
dispatch(Model.Actions.KeyUp({key: keyPress, scancode: 1, time}));
3940
runEffects();
4041
};
4142

42-
input("j");
43+
input('j');
4344

4445
wait(~name="plugin notification shows up", (state: State.t) => {
4546
let notifications = Feature_Notification.all(state.notifications);

‎integration_test/VimSimpleRemapTest.re

+11-10
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,28 @@ runTest(~name="VimSimpleRemapTest", (dispatch, wait, runEffects) => {
1313
runEffects();
1414

1515
let input = key => {
16-
let scancode = Sdl2.Scancode.ofName(key);
17-
let keycode = Sdl2.Keycode.ofName(key);
1816
let modifiers = EditorInput.Modifiers.none;
1917

2018
let keyPress: EditorInput.KeyPress.t =
21-
EditorInput.KeyPress.physicalKey(~scancode, ~keycode, ~modifiers);
19+
EditorInput.KeyPress.physicalKey(
20+
~key=EditorInput.Key.Character(key),
21+
~modifiers,
22+
);
2223
let time = Revery.Time.now();
2324

24-
dispatch(Model.Actions.KeyDown(keyPress, time));
25-
dispatch(Model.Actions.KeyUp(keyPress, time));
25+
dispatch(Model.Actions.KeyDown({key: keyPress, scancode: 1, time}));
26+
dispatch(Model.Actions.KeyUp({key: keyPress, scancode: 1, time}));
2627
runEffects();
2728
};
2829

29-
input("i");
30+
input('i');
3031
wait(~name="Mode is now insert", (state: State.t) =>
3132
Selectors.mode(state) |> Vim.Mode.isInsert
3233
);
3334

34-
input("a");
35-
input("j");
36-
input("j");
35+
input('a');
36+
input('j');
37+
input('j');
3738

3839
wait(~name="Mode is back to normal", (state: State.t) =>
3940
Selectors.mode(state) |> Vim.Mode.isNormal
@@ -57,7 +58,7 @@ runTest(~name="VimSimpleRemapTest", (dispatch, wait, runEffects) => {
5758

5859
// #2601 - Make sure we're _actually_ in normal mode!
5960
// Type another 'j' to see...
60-
input("j");
61+
input('j');
6162

6263
wait(
6364
~name=
+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
open Oni_Model;
2+
open Oni_IntegrationTestLib;
3+
4+
runTest(~name="Viml Remap ; -> :", (dispatch, wait, runEffects) => {
5+
wait(~name="Initial mode is normal", (state: State.t) =>
6+
Selectors.mode(state) |> Vim.Mode.isNormal
7+
);
8+
9+
dispatch(
10+
VimExecuteCommand({allowAnimation: true, command: "nnoremap ; :"}),
11+
);
12+
runEffects();
13+
14+
let input = key => {
15+
let modifiers = EditorInput.Modifiers.none;
16+
17+
let keyPress: EditorInput.KeyPress.t =
18+
EditorInput.KeyPress.physicalKey(
19+
~key=EditorInput.Key.Character(key),
20+
~modifiers,
21+
);
22+
let time = Revery.Time.now();
23+
24+
dispatch(Model.Actions.KeyDown({key: keyPress, scancode: 1, time}));
25+
dispatch(Model.Actions.KeyUp({key: keyPress, scancode: 1, time}));
26+
runEffects();
27+
};
28+
29+
// Because of our remap, the ';' semicolon
30+
// is mapped to ':' - so sending it should open the command line.
31+
input(';');
32+
33+
wait(~name="Mode switches to command line", (state: State.t) => {
34+
Selectors.mode(state) == Vim.Mode.CommandLine
35+
});
36+
37+
input('e');
38+
39+
wait(~name="'e' key is entered", (state: State.t) =>
40+
switch (state.quickmenu) {
41+
| Some(quickmenu) =>
42+
quickmenu.inputText |> Component_InputText.value == "e"
43+
| None => false
44+
}
45+
);
46+
47+
input('h');
48+
49+
wait(~name="'h' key is entered", (state: State.t) =>
50+
switch (state.quickmenu) {
51+
| Some(quickmenu) =>
52+
quickmenu.inputText |> Component_InputText.value == "eh"
53+
| None => false
54+
}
55+
);
56+
});

‎integration_test/dune

+7-6
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
SCMGitTest SyntaxHighlightTextMateTest SyntaxHighlightTreesitterTest
2121
AddRemoveSplitTest TerminalSetPidTitleTest TerminalConfigurationTest
2222
TypingBatchedTest TypingUnbatchedTest VimSimpleRemapTest
23-
ClipboardChangeTest VimScriptLocalFunctionTest ZenModeSingleFileModeTest
24-
ZenModeSplitTest)
23+
VimlRemapCmdlineTest ClipboardChangeTest VimScriptLocalFunctionTest
24+
ZenModeSingleFileModeTest ZenModeSplitTest)
2525
(libraries Oni_CLI Oni_IntegrationTestLib reason-native-crash-utils.asan))
2626

2727
(install
@@ -54,7 +54,8 @@
5454
SyntaxServerReadExceptionTest.exe TerminalSetPidTitleTest.exe
5555
TerminalConfigurationTest.exe AddRemoveSplitTest.exe TypingBatchedTest.exe
5656
TypingUnbatchedTest.exe VimScriptLocalFunctionTest.exe
57-
VimSimpleRemapTest.exe ZenModeSingleFileModeTest.exe ZenModeSplitTest.exe
58-
ClipboardChangeTest.exe large-c-file.c lsan.supp some-test-file.json
59-
some-test-file.txt test.crlf test.lf utf8.txt utf8-test-file.htm
60-
Inconsolata-Regular.ttf PlugScriptLocal.vim))
57+
VimSimpleRemapTest.exe VimlRemapCmdlineTest.exe
58+
ZenModeSingleFileModeTest.exe ZenModeSplitTest.exe ClipboardChangeTest.exe
59+
large-c-file.c lsan.supp some-test-file.json some-test-file.txt test.crlf
60+
test.lf utf8.txt utf8-test-file.htm Inconsolata-Regular.ttf
61+
PlugScriptLocal.vim))

0 commit comments

Comments
 (0)
Please sign in to comment.