diff --git a/src/apitest/cmdline_search.c b/src/apitest/cmdline_search.c index 5f8194064..048a40c89 100644 --- a/src/apitest/cmdline_search.c +++ b/src/apitest/cmdline_search.c @@ -137,12 +137,30 @@ MU_TEST(test_insert_literal_ctrl_q) mu_check(strcmp(vimSearchGetPattern(), "~7") == 0); } +MU_TEST(test_search_end) +{ + // Regression test for Onivim: + // https://github.com/onivim/oni2/issues/3704 + vimInput("/"); + vimInput("t"); + vimInput("s"); + vimInput("t"); + vimInput("/"); + vimInput("e"); + mu_check(strcmp(vimSearchGetPattern(), "tst") == 0); + + vimKey(""); + // This was the part that failed in Onivim #3704: + mu_check(strcmp(vimSearchGetPattern(), "tst") == 0); +} + MU_TEST_SUITE(test_suite) { MU_SUITE_CONFIGURE(&test_setup, &test_teardown); MU_RUN_TEST(test_cancel_inc_search); MU_RUN_TEST(test_search_forward_esc); + MU_RUN_TEST(test_search_end); MU_RUN_TEST(test_cancel_n); MU_RUN_TEST(test_get_search_highlights_during_visual); MU_RUN_TEST(test_insert_literal_ctrl_v); diff --git a/src/normal.c b/src/normal.c index 49097e715..e169f77e7 100644 --- a/src/normal.c +++ b/src/normal.c @@ -673,13 +673,13 @@ executionStatus_T state_normal_cmd_execute(void *ctx, int c) /* Seed the search - bump it forward and back so everything is set for N and n */ if (cmdc == '/') { - (void)normal_search(&context->ca, cmdc, cmd, 0); - (void)normal_search(&context->ca, cmdc, cmd, SEARCH_REV | SEARCH_END); + (void)normal_search(&context->ca, cmdc, get_search_pat(), 0); + (void)normal_search(&context->ca, cmdc, get_search_pat(), SEARCH_REV | SEARCH_END); } else { - (void)normal_search(&context->ca, cmdc, cmd, SEARCH_START); - (void)normal_search(&context->ca, cmdc, cmd, SEARCH_REV | SEARCH_START); + (void)normal_search(&context->ca, cmdc, get_search_pat(), SEARCH_START); + (void)normal_search(&context->ca, cmdc, get_search_pat(), SEARCH_REV | SEARCH_START); } /* TODO: SEARCH_MARK parameter - how do we wire that up? We may need to stash save_cursor somewhere. */