Fix tab handling when no completion is available.

This commit is contained in:
antirez
2026-02-14 13:11:08 +01:00
parent ef81d1e1c9
commit 452e379385
2 changed files with 17 additions and 0 deletions

View File

@@ -1239,6 +1239,21 @@ static void test_multiline_history(void) {
test_end();
}
static void test_tab_no_completions(void) {
if (test_start("TAB With No Completions", "./linenoise-example") == -1) return;
/* Type "foo" then TAB: no completions for "foo", TAB should be consumed. */
send_keys("foo");
send_keys("\t");
/* Type more text: should appear right after "foo" with no TAB inserted. */
send_keys("bar");
assert_screen_row(0, "hello> foobar");
assert_cursor(0, strlen("hello> foobar"));
test_end();
}
/* ========================= Main ========================= */
int main(int argc, char **argv) {
@@ -1267,6 +1282,7 @@ int main(int argc, char **argv) {
test_emulator_grapheme_storage();
test_ctrl_w_delete_word();
test_ctrl_u_delete_line();
test_tab_no_completions();
/* Horizontal scrolling tests (single-line mode). */
test_horizontal_scroll();

View File

@@ -723,6 +723,7 @@ static int completeLine(struct linenoiseState *ls, int keypressed) {
if (lc.len == 0) {
linenoiseBeep();
ls->in_completion = 0;
c = 0;
} else {
switch(c) {
case 9: /* tab */