feat: cycle command completions backward with Shift+Tab

This commit is contained in:
2026-10-17 18:23:04 +02:00
parent 5d75964ee2
commit 0a01d9a361
6 changed files with 83 additions and 17 deletions
+48 -2
View File
@@ -1080,8 +1080,10 @@ fn command_completion_cycles_core_alias_and_live_plugin_names_without_executing(
assert_eq!(editor.context().text, document);
assert!(!editor.should_quit());
}
editor.handle(Input::Char('\t'));
editor.handle(Input::Char('\t'));
for expected in ["save_note", "save_and_quit", "save", "save_note"] {
assert_eq!(editor.handle(Input::BackTab), None);
assert_eq!(editor.command_line(), expected);
}
let invocation = editor.handle(Input::Enter).unwrap();
assert_eq!(invocation.plugin, "fixture");
assert_eq!(invocation.command, "save_note");
@@ -1103,6 +1105,50 @@ fn command_completion_cycles_core_alias_and_live_plugin_names_without_executing(
}
}
#[test]
fn command_completion_reverse_starts_at_last_match_and_retains_prefix_on_direction_changes() {
let mut editor = editor();
type_text(&mut editor, ":tab.");
for (key, expected) in [
(Input::BackTab, "tab.previous"),
(Input::BackTab, "tab.next"),
(Input::Char('\t'), "tab.previous"),
(Input::Char('\t'), "tab.close"),
(Input::BackTab, "tab.previous"),
] {
editor.handle(key);
assert_eq!(editor.command_line(), expected);
assert_eq!(editor.tab_count(), 1);
}
editor.handle(Input::Escape);
for draft in ["plugins", "unknown", "界", "edit file name"] {
type_text(&mut editor, ":");
type_text(&mut editor, draft);
for _ in 0..2 {
editor.handle(Input::BackTab);
assert_eq!(editor.command_line(), draft);
}
editor.handle(Input::Escape);
}
editor.bind("command", "shift+tab", None).unwrap();
editor
.bind(
"command",
"ctrl+b",
Some("core.command_complete_previous".into()),
)
.unwrap();
type_text(&mut editor, ":tab.");
editor.handle(Input::BackTab);
assert_eq!(editor.command_line(), "tab.");
editor.handle(Input::Ctrl('b'));
assert_eq!(editor.command_line(), "tab.previous");
editor.handle(Input::Char('\t'));
assert_eq!(editor.command_line(), "tab.close");
editor.handle(Input::Ctrl('b'));
assert_eq!(editor.command_line(), "tab.previous");
}
#[test]
fn command_completion_restarts_after_edits_history_and_cancellation_and_ignores_arguments() {
let mut editor = editor();