Scripts: the warning lists a script's needs apart from what it reaches

A need such as dialogs or host features now shows on its own line, and
the "Outside the document" heading appears only above what the script
does outside the document.
This commit is contained in:
dotCooCoo committed 2026-11-25 04:00:21 -08:00
1 parent 263223d604
commit 2b155a5de1
2 files changed
+20 -5

No files matched your search

+6 -5
View File
@@ -592,11 +592,12 @@ fn listed(prompt: StandardPrompt, r: &Value) -> StandardPrompt {
})
.collect();
let needs = list(r, "needs").iter().filter_map(Value::as_str).filter(|n| matches!(*n, "files" | "dialogs" | "hostOnly")).filter_map(need_label);
let mut lines: Vec<String> = Vec::new();
lines.extend(outside);
lines.extend(needs.map(str::to_string));
if !lines.is_empty() {
lines.insert(0, crate::i18n::colon(tl!("Outside the document")));
// The needs come first, each a sentence of its own; the heading names only what the script does
// outside the document.
let mut lines: Vec<String> = needs.map(str::to_string).collect();
if !outside.is_empty() {
lines.push(crate::i18n::colon(tl!("Outside the document")));
lines.extend(outside);
}
let includes = list(r, "includes");
if !includes.is_empty() {
+14
View File
@@ -541,6 +541,20 @@ fn the_warning_lists_what_a_scripts_included_files_reach() {
let _ = std::fs::remove_dir_all(&dir);
}
/// A script that opens a dialog and reaches nothing outside the document lists the need without the
/// outside-the-document heading.
#[test]
fn the_warning_lists_a_need_without_the_outside_heading() {
let mut app = app();
menus::run_ui_command(&mut app, "ui.runScript", &json!({"source": "var w = new Window('dialog', 'Title');", "name": "dialog.js"})).unwrap().unwrap();
assert_eq!(fields(&app, KIND)["reaches"]["outside"], json!([]));
let texts = dialog_texts(&mut app);
assert!(texts.iter().any(|t| t == script_check::need_label("dialogs").unwrap()), "{texts:?}");
assert!(!texts.iter().any(|t| t == "Outside the document:"), "{texts:?}");
cancel(&mut app, KIND);
finish(&mut app);
}
/// A script file that changes what it reaches while its warning is open does not run on Run: the
/// warning opens again with the new report, and the next Run runs it.
#[test]