From b8b1a3a6a25bd89565a19c151a82ee951dc38e3d Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 28 Oct 2026 06:33:44 -0700 Subject: [PATCH] Run the File > Scripts entry when a panel shares its name File > Scripts lists a bundled script even when an installed ScriptUI panel has the same name, but running it by name opened the panel. A script now runs before a panel of the same name, and it enters Recent Script Files. --- crates/engine/src/cmd/scripts.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/engine/src/cmd/scripts.rs b/crates/engine/src/cmd/scripts.rs index 58da7bd49..0f1f377a5 100644 --- a/crates/engine/src/cmd/scripts.rs +++ b/crates/engine/src/cmd/scripts.rs @@ -235,9 +235,11 @@ fn uninstall(s: &mut Session, p: &Value) -> Result { } /// Run an installed or bundled script by name (File ▸ Scripts ▸ ``). A ScriptUI panel run -/// this way gets `this` = a floating palette-like panel window. +/// this way gets `this` = a floating palette-like panel window. A script listed under File ▸ +/// Scripts runs before a panel of the same name. pub(crate) fn run_named(s: &mut Session, name: &str) -> Result { - let (panel, code) = script_code(s, name, None).ok_or_else(|| bad("file.runScript", format!("no installed or bundled script `{name}`")))?; + let found = script_code(s, name, Some(false)).or_else(|| script_code(s, name, None)); + let (panel, code) = found.ok_or_else(|| bad("file.runScript", format!("no installed or bundled script `{name}`")))?; if panel { return open_panel(s, &json!({"name": name})); } @@ -612,8 +614,10 @@ mod tests { std::fs::write(root.join("settings").join(PANELS_DIR).join(name), "panel").unwrap(); assert!(super::scripts(&s).iter().any(|entry| entry.name == name && !entry.panel)); assert!(script_code(&s, name, None).unwrap().0); - s.execute("file.runScript", json!({"name": name})).unwrap(); - assert!(s.prefs.recent_scripts.is_empty(), "the selected panel must not enter recent script history"); + let sample = BUNDLED.iter().find(|b| b.0 == name).unwrap().3; + assert_eq!(s.execute("file.runScript", json!({"name": name})).unwrap()["ran"], sample); + assert!(super::open_panel_names(&s).is_empty(), "the listed script runs instead of the panel"); + assert_eq!(s.prefs.recent_scripts, [crate::prefs::RecentScript::Name(name.to_string())]); let _ = std::fs::remove_dir_all(root); }