feat(commandline): always-on keyboard capture + space submits like enter

Two behaviour changes that bring the command line in line with
established CAD workflow:

1. **Always-on keyboard capture.** The input was blurred whenever no
   command was running, so typed letters went nowhere until the user
   clicked into the field. Replace the blur with a re-focus on every
   command lifecycle transition (cmd_result.rs) and on viewport / tab
   / ribbon clicks (update.rs), focus the input at startup, and add
   a global key subscription that catches any unhandled character key
   or backspace and routes it into the buffer via two new messages
   (CommandAppendChar / CommandBackspace) — so the command line keeps
   accumulating keystrokes even if focus parks somewhere not
   focusable. Removes the unused blur_cmd_input helper.

2. **Space submits.** Typing a space at the end of the input now
   submits the buffer the same way Enter does. Only exception: an
   active command that's currently collecting free-form prose
   (TEXT / MTEXT / DDEDIT body, ATTDEF prompt / default value,
   INSERT attribute value, ATTEDIT cell). Those advertise the new
   `CadCommand::wants_text_with_spaces()` flag so the Space character
   reaches the buffer as a literal.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Hakan Seven 2026-05-26 18:59:51 +03:00
commit 39150d617f
16 changed files with 136 additions and 42 deletions

View file

@ -678,6 +678,11 @@ impl OpenCADStudio {
{
Some(Message::DeleteSelected)
}
keyboard::Key::Named(keyboard::key::Named::Backspace)
if status == Status::Ignored =>
{
Some(Message::CommandBackspace)
}
keyboard::Key::Named(keyboard::key::Named::ArrowUp) => {
Some(Message::CommandHistoryPrev)
}
@ -718,6 +723,15 @@ impl OpenCADStudio {
"v" => Some(Message::Command("PASTECLIP".to_string())),
_ => None,
},
// Plain character keys (no ctrl) that nothing
// else consumed — route them into the command
// line input so typing always reaches it even
// when focus is parked on a button / viewport.
keyboard::Key::Character(c)
if !ctrl && status == Status::Ignored =>
{
Some(Message::CommandAppendChar(c.to_string()))
}
_ => None,
}
}
@ -730,11 +744,6 @@ impl OpenCADStudio {
pub(super) fn focus_cmd_input(&self) -> Task<Message> {
iced::widget::operation::focus(iced::widget::Id::new(crate::ui::command_line::CMD_INPUT_ID))
}
pub(super) fn blur_cmd_input(&self) -> Task<Message> {
let op = iced::advanced::widget::operation::focusable::unfocus::<Message>();
iced::advanced::widget::operate(op)
}
}
// ── Paper canvas ──────────────────────────────────────────────────────────