Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing commands one character at a time breaks keybinds #184

Open
tristil opened this issue Mar 20, 2020 · 1 comment
Open

Passing commands one character at a time breaks keybinds #184

tristil opened this issue Mar 20, 2020 · 1 comment

Comments

@tristil
Copy link

tristil commented Mar 20, 2020

Describe the bug

If input is passed to vimInput one character at a time a multi-character keybind (for example inoremap jk <esc>) will fail. The first key will be swallowed up and the second will be inputted, without leaving insert mode.

To Reproduce

This test passes

diff --git a/src/apitest/insert_mode.c b/src/apitest/insert_mode.c
index bb87cfe01..ff8e3f68b 100644
--- a/src/apitest/insert_mode.c
+++ b/src/apitest/insert_mode.c
@@ -168,6 +168,19 @@ MU_TEST(insert_mode_ctrlv_newline)
   mu_check(line[0] == 13);
 }

+MU_TEST(insert_mode_exits_with_keybind)
+{
+  vimExecute("inoremap jk <esc>");
+  vimInput("i");
+  vimInput("jk");
+
+  mu_check((vimGetMode() & NORMAL) == NORMAL);
+
+  char_u *line = vimBufferGetLine(curbuf, vimCursorGetLine());
+  printf("LINE: %s\n", line);
+  mu_check(strcmp(line, "abc") == 0);
+}
+
 MU_TEST_SUITE(test_suite)
 {
   MU_SUITE_CONFIGURE(&test_setup, &test_teardown);
@@ -182,6 +195,7 @@ MU_TEST_SUITE(test_suite)
   MU_RUN_TEST(insert_mode_ctrlv);
   MU_RUN_TEST(insert_mode_ctrlv_no_digit);
   MU_RUN_TEST(insert_mode_ctrlv_newline);
+  MU_RUN_TEST(insert_mode_exits_with_keybind);
 }

whereas this test fails

diff --git a/src/apitest/insert_mode.c b/src/apitest/insert_mode.c
index bb87cfe01..837cae897 100644
--- a/src/apitest/insert_mode.c
+++ b/src/apitest/insert_mode.c
@@ -168,6 +168,20 @@ MU_TEST(insert_mode_ctrlv_newline)
   mu_check(line[0] == 13);
 }

+MU_TEST(insert_mode_exits_with_keybind)
+{
+  vimExecute("inoremap jk <esc>");
+  vimInput("i");
+  vimInput("j");
+  vimInput("k");
+
+  mu_check((vimGetMode() & NORMAL) == NORMAL);
+
+  char_u *line = vimBufferGetLine(curbuf, vimCursorGetLine());
+  printf("LINE: %s\n", line);
+  mu_check(strcmp(line, "abc") == 0);
+}
+
 MU_TEST_SUITE(test_suite)
 {
   MU_SUITE_CONFIGURE(&test_setup, &test_teardown);
@@ -182,6 +196,7 @@ MU_TEST_SUITE(test_suite)
   MU_RUN_TEST(insert_mode_ctrlv);
   MU_RUN_TEST(insert_mode_ctrlv_no_digit);
   MU_RUN_TEST(insert_mode_ctrlv_newline);
+  MU_RUN_TEST(insert_mode_exits_with_keybind);
 }

Expected behavior

Oni2 sends keystrokes one at a time to vimInput. Because of this, the above behavior is blocking implementing Spacemacs-like keybindings. I would like to see this fixed here or for some other solution for spooling keypress before sending to vimInput implemented on the Oni2 side.

@glennsl
Copy link
Member

glennsl commented Mar 20, 2020

Related: onivim/oni2#741, onivim/oni2#382, #101

I think this is currently being worked on in https://github.com/onivim/editor-input though, if I understood @bryphe correctly. And if so the solution is in a layer above libvim.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants