feat: add searchable command palette
This commit is contained in:
@@ -155,6 +155,69 @@ Vamp.command("healthy") { |editor, args| editor.replace "healthy #{args}" }
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn typed_palette_binding_prepares_arguments_and_retires_failed_plugin_commands() {
|
||||
let fixture = Fixture::new();
|
||||
fixture.file("buffer.txt", "base");
|
||||
fixture.file(
|
||||
"palette.rb",
|
||||
r#"
|
||||
Vamp.plugin "palette_fixture", requires: ["text"]
|
||||
Vamp.command("palette_insert") { |editor, args| editor.insert args }
|
||||
Vamp.command("palette_fail") { |_, _| raise "palette fixture failure" }
|
||||
"#,
|
||||
);
|
||||
let mut session = fixture.open(
|
||||
r#"
|
||||
Vamp.configure do |config|
|
||||
config.plugin "palette.rb"
|
||||
config.bind "ctrl+p", nil
|
||||
config.bind "ctrl+f", config.core.palette
|
||||
end
|
||||
"#,
|
||||
);
|
||||
session.handle(Input::Ctrl('p'));
|
||||
assert!(session.editor().palette().is_none());
|
||||
session.handle(Input::Ctrl('f'));
|
||||
for ch in "palette_insert".chars() {
|
||||
session.handle(Input::Char(ch));
|
||||
}
|
||||
assert_eq!(
|
||||
session.editor().palette().unwrap().entries[0].owner,
|
||||
"palette_fixture"
|
||||
);
|
||||
session.handle(Input::Enter);
|
||||
assert_eq!(session.editor().mode(), crate::editor::Mode::Command);
|
||||
assert_eq!(session.editor().command_line(), "palette_insert ");
|
||||
assert_eq!(session.editor().lines(), &["base"]);
|
||||
for ch in "界!".chars() {
|
||||
session.handle(Input::Char(ch));
|
||||
}
|
||||
session.handle(Input::Enter);
|
||||
assert_eq!(session.editor().lines(), &["界!base"]);
|
||||
session.handle(Input::Char('u'));
|
||||
assert_eq!(session.editor().lines(), &["base"]);
|
||||
session.handle(Input::Ctrl('f'));
|
||||
for ch in "palette_fail".chars() {
|
||||
session.handle(Input::Char(ch));
|
||||
}
|
||||
session.handle(Input::Enter);
|
||||
session.handle(Input::Enter);
|
||||
assert!(session.editor().message().contains("disabled"));
|
||||
session.handle(Input::Ctrl('f'));
|
||||
assert!(
|
||||
!session
|
||||
.editor()
|
||||
.palette()
|
||||
.unwrap()
|
||||
.entries
|
||||
.iter()
|
||||
.any(|entry| entry.owner == "palette_fixture")
|
||||
);
|
||||
session.handle(Input::Escape);
|
||||
assert_eq!(session.editor().lines(), &["base"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn configured_selection_actions_edit_together_and_invoke_plugins_once() {
|
||||
let fixture = Fixture::new();
|
||||
|
||||
Reference in New Issue
Block a user