forked from 1b-agent/opencadstudio-upstream
fix(commands): record last_cmd on plugin dispatch to repeat on Enter
When a plugin command was dispatched, record_recent was called but tabs[i].last_cmd was never set. Consequently, pressing Enter or Space on an empty command line after running a plugin command failed to repeat it. This records tabs[i].last_cmd on plugin dispatch and requests command-line focus and dynamic input syncing when an interactive plugin command starts.
This commit is contained in:
1 parent
460a4c9cc5
commit
7c0af700e8
2 files changed
+43
-2
No files matched your search
@@ -731,6 +731,8 @@ impl OpenCADStudio {
|
|||||||
// (`LINE`), so the full line is not a plugin command and falls through to
|
// (`LINE`), so the full line is not a plugin command and falls through to
|
||||||
// the first-word + fed-tokens path below. (#162)
|
// the first-word + fed-tokens path below. (#162)
|
||||||
if !self.suppress_plugin_dispatch && crate::plugin::try_dispatch(self, i, cmd) {
|
if !self.suppress_plugin_dispatch && crate::plugin::try_dispatch(self, i, cmd) {
|
||||||
|
self.tabs[i].last_cmd = Some(cmd.to_string());
|
||||||
|
self.command_line.record_recent(cmd);
|
||||||
let toks: Vec<String> = tokens.iter().map(|s| s.to_string()).collect();
|
let toks: Vec<String> = tokens.iter().map(|s| s.to_string()).collect();
|
||||||
return self.finish_active_command(&toks, finish);
|
return self.finish_active_command(&toks, finish);
|
||||||
}
|
}
|
||||||
|
|||||||
+41
-2
@@ -197,11 +197,15 @@ impl OpenCADStudio {
|
|||||||
// tool was a one-shot and we must turn the ribbon highlight off here —
|
// tool was a one-shot and we must turn the ribbon highlight off here —
|
||||||
// normally apply_cmd_result does that, but plugin dispatch can return
|
// normally apply_cmd_result does that, but plugin dispatch can return
|
||||||
// without producing a CmdResult.
|
// without producing a CmdResult.
|
||||||
|
self.tabs[i].last_cmd = Some(cmd.to_string());
|
||||||
self.command_line.record_recent(cmd);
|
self.command_line.record_recent(cmd);
|
||||||
if self.tabs[i].active_cmd.is_none() {
|
if self.tabs[i].active_cmd.is_none() {
|
||||||
self.ribbon.deactivate_tool();
|
self.ribbon.deactivate_tool();
|
||||||
|
return Task::none();
|
||||||
|
} else {
|
||||||
|
self.sync_dyn_fields();
|
||||||
|
return self.focus_cmd_input();
|
||||||
}
|
}
|
||||||
return Task::none();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command families are dispatched in source order (see
|
// Command families are dispatched in source order (see
|
||||||
@@ -822,7 +826,7 @@ inventory::submit!(crate::command::CommandRegistration {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod marquee_cancel_tests {
|
mod marquee_cancel_tests {
|
||||||
use crate::app::{GripPendingValue, OpenCADStudio};
|
use crate::app::{GripPendingValue, Message, OpenCADStudio};
|
||||||
use crate::scene::model::object::GripMenuAction;
|
use crate::scene::model::object::GripMenuAction;
|
||||||
use crate::scene::pick::grip::GripEdit;
|
use crate::scene::pick::grip::GripEdit;
|
||||||
use codec::Handle;
|
use codec::Handle;
|
||||||
@@ -968,4 +972,39 @@ mod marquee_cancel_tests {
|
|||||||
Some("LINE")
|
Some("LINE")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn command_finalize_repeats_last_cmd() {
|
||||||
|
let mut app = fresh();
|
||||||
|
let i = app.active_tab;
|
||||||
|
assert_eq!(app.tabs[i].last_cmd, None);
|
||||||
|
|
||||||
|
// Run LINE command
|
||||||
|
let _ = app.dispatch_command("LINE");
|
||||||
|
assert_eq!(app.tabs[i].last_cmd.as_deref(), Some("LINE"));
|
||||||
|
|
||||||
|
// Cancel LINE with Escape
|
||||||
|
let _ = app.update(Message::CommandEscape);
|
||||||
|
assert!(app.tabs[i].active_cmd.is_none());
|
||||||
|
assert_eq!(app.tabs[i].last_cmd.as_deref(), Some("LINE"));
|
||||||
|
|
||||||
|
// Press Enter (CommandFinalize) on empty command line repeats LINE
|
||||||
|
let _ = app.update(Message::CommandFinalize);
|
||||||
|
assert_eq!(
|
||||||
|
app.tabs[i].active_cmd.as_deref().map(|cmd| cmd.name()),
|
||||||
|
Some("LINE")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn empty_enter_repeats_plugin_command() {
|
||||||
|
let mut app = fresh();
|
||||||
|
let i = app.active_tab;
|
||||||
|
app.tabs[i].last_cmd = Some("TARC".to_string());
|
||||||
|
|
||||||
|
// When idle, CommandFinalize repeats last_cmd
|
||||||
|
let _ = app.update(Message::CommandFinalize);
|
||||||
|
// Confirms TARC was re-dispatched when empty Enter was pressed
|
||||||
|
assert!(app.command_line.last_error.as_deref().unwrap_or("").contains("TARC"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user