M1.8: command palette, global keymap, UI commands
- Engine: ui.registerCommands (validated, replaces the previous set),
UI commands in listCommands with ui: true and labelKey, running one
through the engine emits uiCommand {id, params}.
- Frontend: ui/src/commands/ (keymap by key code, fuzzy ranking, Pinia
commands store with handlers, recents and error toasts), the command
palette (Mod+Shift+P), UI commands palette.open, settings.open (Mod+,,
disabled until M1.9b) and view.toggleProjectTree (Mod+1). The editor's
shortcuts.ts moved into the global keymap.
- Tests: engine and control-channel tests for registration and
uiCommand, Vitest for keymap, ranking, store, palette and App wiring.
- Docs: architecture, ui-parity, target-app-parity, gaps, roadmap,
ROADMAP, README.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
2f8fef876b
commit
184b8a3468
33 changed files with 2282 additions and 233 deletions
|
|
@ -66,6 +66,7 @@ impl Engine {
|
|||
pub fn new() -> Result<Self, EngineError> {
|
||||
let mut engine = Self::empty();
|
||||
cmd::register_builtins(&mut engine.registry)?;
|
||||
engine.state.engine_commands = engine.registry.ids().collect();
|
||||
Ok(engine)
|
||||
}
|
||||
|
||||
|
|
@ -82,7 +83,10 @@ impl Engine {
|
|||
/// # Errors
|
||||
/// Returns [`EngineError::Internal`] if the id is already taken.
|
||||
pub fn register(&mut self, command: Box<dyn Command>) -> Result<(), EngineError> {
|
||||
self.registry.register(command)
|
||||
let id = command.spec().id;
|
||||
self.registry.register(command)?;
|
||||
self.state.engine_commands.insert(id);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Runs a command inside the guard. On success the outcome carries every
|
||||
|
|
@ -97,11 +101,18 @@ impl Engine {
|
|||
/// [`EngineError::UnknownCommand`] for an unknown id,
|
||||
/// [`EngineError::Disabled`] if the command is disabled, the command's own
|
||||
/// error, or [`EngineError::Internal`] if it panicked.
|
||||
///
|
||||
/// A UI command registered with `ui.registerCommands` is not run here:
|
||||
/// the engine queues `uiCommand` for the frontend and returns `null`.
|
||||
pub fn execute(&mut self, id: &str, params: Value) -> Result<Outcome, EngineError> {
|
||||
let Self { registry, state } = self;
|
||||
let command = registry
|
||||
.get(id)
|
||||
.ok_or_else(|| EngineError::UnknownCommand(id.to_string()))?;
|
||||
let Some(command) = registry.get(id) else {
|
||||
let mut outcome = cmd::ui::dispatch(state, id, params)
|
||||
.ok_or_else(|| EngineError::UnknownCommand(id.to_string()))?;
|
||||
state.commands_run = state.commands_run.saturating_add(1);
|
||||
outcome.events = state.take_events();
|
||||
return Ok(outcome);
|
||||
};
|
||||
let result = guard::run(|| {
|
||||
if !command.enabled(state) {
|
||||
return Err(EngineError::Disabled(id.to_string()));
|
||||
|
|
@ -180,16 +191,26 @@ impl Engine {
|
|||
self.state.take_events()
|
||||
}
|
||||
|
||||
/// Describes every command with its current enabled state. A command whose
|
||||
/// `enabled` check panics is listed as disabled.
|
||||
/// Describes every command with its current enabled state, the
|
||||
/// engine's and the registered UI commands (`ui: true`), in id order.
|
||||
/// A command whose `enabled` check panics is listed as disabled.
|
||||
pub fn list_commands(&self) -> Vec<CommandInfo> {
|
||||
self.registry
|
||||
let mut list: Vec<CommandInfo> = self
|
||||
.registry
|
||||
.iter()
|
||||
.map(|c| {
|
||||
let enabled = guard::run(|| Ok(c.enabled(&self.state))).unwrap_or(false);
|
||||
CommandInfo::new(c.spec(), enabled)
|
||||
})
|
||||
.collect()
|
||||
.chain(
|
||||
self.state
|
||||
.ui_commands
|
||||
.values()
|
||||
.map(cmd::ui::UiCommand::info),
|
||||
)
|
||||
.collect();
|
||||
list.sort_by(|a, b| a.id.cmp(&b.id));
|
||||
list
|
||||
}
|
||||
|
||||
/// Read access to the state.
|
||||
|
|
@ -359,6 +380,7 @@ mod tests {
|
|||
"test.disabled",
|
||||
"theme.list",
|
||||
"theme.systemPreference",
|
||||
"ui.registerCommands",
|
||||
]
|
||||
);
|
||||
let by_id = |id: &str| list.iter().find(|c| c.id == id).unwrap();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue