From 32a65a4a76823b6bf79a9999175ee00a7f331345 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Sat, 7 Nov 2026 15:53:03 -0500 Subject: [PATCH 1/2] feat(ui): a Clear button empties the Script pane, its script back with Ctrl+Z --- crates/ui-egui/src/analysispane.rs | 97 +++++++++++++++++++++++++++--- docs/user-guide/analysis.md | 5 +- 2 files changed, 94 insertions(+), 8 deletions(-) diff --git a/crates/ui-egui/src/analysispane.rs b/crates/ui-egui/src/analysispane.rs index 209a6a89bc..6bb4eead59 100644 --- a/crates/ui-egui/src/analysispane.rs +++ b/crates/ui-egui/src/analysispane.rs @@ -1566,13 +1566,37 @@ pub fn script_pane(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { /// [`script_ran`] keeps it out of the pane; its notice stays among the session's. fn start_over_in_another_project(app: &mut RustGisApp) { let opened = app.session.opened; - let w = &mut app.workflow; - if w.script_project.is_some_and(|p| p != opened) { - w.script.clear(); - w.script_out.clear(); - w.script_last = None; + if app.workflow.script_project.is_some_and(|p| p != opened) { + clear_script(app); } - w.script_project = Some(opened); + app.workflow.script_project = Some(opened); +} + +/// Clear: the pane emptied, as one undo step of the box, which keeps the focus, so its own Ctrl+Z +/// brings the script back at once. The box records undo steps only while it has the focus, so +/// the script is kept as one here, as a suggestion picked keeps the text it replaced +/// (`scriptcomplete::accept`). +fn clear_script_pane(app: &mut RustGisApp, ui: &Ui, box_id: egui::Id) { + use egui::text::{CCursor, CCursorRange}; + let mut state = egui::widgets::text_edit::TextEditState::load(ui.ctx(), box_id).unwrap_or_default(); + let mut undoer = state.undoer(); + let end = CCursorRange::one(CCursor::new(app.workflow.script.chars().count())); + undoer.add_undo(&(state.cursor.char_range().unwrap_or(end), app.workflow.script.clone())); + state.set_undoer(undoer); + state.cursor.set_char_range(Some(CCursorRange::one(CCursor::new(0)))); + state.store(ui.ctx(), box_id); + clear_script(app); + ui.memory_mut(|m| m.request_focus(box_id)); +} + +/// The Script pane emptied: its script, results and count, so the next run is `Run #1`, and the +/// Details window with the run it showed. Clear does it, and another project opening. +fn clear_script(app: &mut RustGisApp) { + let w = &mut app.workflow; + w.script.clear(); + w.script_out.clear(); + w.script_last = None; + w.script_details = false; } /// The height of the Script box's first lines. @@ -1731,7 +1755,8 @@ fn script(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens, fit: bool) { } ui.horizontal(|ui| { // As egui reads the keys: ⌘ on a Mac, the browser's too (from its user agent). - let shortcut = if ui.ctx().os().is_mac() { "⌘+Enter" } else { "Ctrl+Enter" }; + let mac = ui.ctx().os().is_mac(); + let shortcut = if mac { "⌘+Enter" } else { "Ctrl+Enter" }; let run = ui.button(tl!("Run")).on_hover_text(crate::i18n::fmt("Run the script ({keys})", &[("keys", shortcut)])).clicked(); if run || ctrl_enter { let script = app.workflow.script.clone(); @@ -1740,6 +1765,20 @@ fn script(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens, fit: bool) { if ui.button(tl!("Commands…")).on_hover_text(tl!("Search every command and its parameters")).clicked() { let _ = app.run("ui.commandSearch", Value::Null); } + // Not while a run is under way: its results would land in the emptied pane. + let w = &app.workflow; + let running = !w.script_started.is_empty(); + let anything = !w.script.is_empty() || !w.script_out.is_empty() || w.script_last.is_some(); + let undo = if mac { "⌘+Z" } else { "Ctrl+Z" }; + let mut clear = ui + .add_enabled(anything && !running, egui::Button::new(tl!("Clear"))) + .on_hover_text(crate::i18n::fmt("Empty the script and its results ({keys} brings the script back)", &[("keys", undo)])); + if running { + clear = clear.on_disabled_hover_text(tl!("Wait for the run to finish")); + } + if clear.clicked() { + clear_script_pane(app, ui, box_id); + } }); // Above the results' scroll, so it stays in view: its number and how long it took, and on // the right when it started, as the Geoprocessing History tells it (UTC: the app has no time @@ -2088,6 +2127,50 @@ mod tests { assert_eq!(app.workflow.script_out, vec![("cancelled".to_string(), true)]); } + /// Clear empties the Script pane as another project opening does (#1511): the script, its + /// results and count, and Details. The box keeps the focus, so Ctrl+Z brings the script back. + /// With nothing to clear, or a run under way, the button is off. + #[test] + fn clear_empties_the_script_pane_and_undo_brings_the_script_back() { + use egui_kittest::kittest::NodeT; + let mut app = RustGisApp::with_sample(); + app.workflow.script = "map.zoomFull".to_string(); + script_ran(&mut app, crate::Landed::Ran(Ok(json!({"ran": [{"line": 1, "command": "map.zoomFull", "result": null}]})))); + // Details open (its window isn't drawn here: it would sit over the button the pointer clicks). + app.workflow.script_details = true; + let mut fonts = false; + let mut h = egui_kittest::Harness::builder().with_size(vec2(900.0, 800.0)).build_ui_state( + move |ui, app: &mut RustGisApp| { + if !fonts { + crate::theme::install_fonts(ui.ctx(), &[], None); + fonts = true; + return; + } + script_pane(app, ui, &Tokens::light()); + }, + app, + ); + h.run(); + let on = |h: &egui_kittest::Harness<'_, RustGisApp>| !h.get_by_label("Clear").accesskit_node().is_disabled(); + assert!(on(&h)); + h.get_by_label("Clear").click(); + h.run(); + let w = &h.state().workflow; + assert!(w.script.is_empty() && w.script_out.is_empty() && w.script_last.is_none(), "script, results and count"); + assert!(!w.script_details, "Details closes with the run it showed"); + assert!(h.get_by_role(egui::accesskit::Role::MultilineTextInput).is_focused(), "the box keeps the focus"); + assert!(!on(&h), "nothing left to clear"); + // The box's own undo brings the script back, with nothing clicked first. + h.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::Z); + h.run(); + assert_eq!(h.state().workflow.script, "map.zoomFull"); + assert!(h.state().workflow.script_last.is_none(), "the results stay gone"); + // A run under way: off, as its results would land in the emptied pane. + h.state_mut().workflow.script_started.push_back((0, web_time::Instant::now(), 0)); + h.run(); + assert!(!on(&h)); + } + /// Details… opens the last run in a window of its own, each line folded: a result the pane cuts /// shows whole there, laid out to read, Copy copies it and Copy All the run; a run that stopped /// shows why. diff --git a/docs/user-guide/analysis.md b/docs/user-guide/analysis.md index 52da164908..71919eb7a1 100644 --- a/docs/user-guide/analysis.md +++ b/docs/user-guide/analysis.md @@ -1178,7 +1178,10 @@ and when it started (`Run #2 (0.84 s)`, and `14:04 UTC` on the right), so a run mistake shows (Undo takes a whole run back). The results show each line's result cut to a line; **Details…** on the run's line opens them whole in a window, as View Details in ArcGIS Pro's Geoprocessing History: each line folded under its command, opening to its result laid out to -read, **Copy** for one and **Copy All** for the run, and why it stopped, if it did. Opening a +read, **Copy** for one and **Copy All** for the run, and why it stopped, if it did. **Clear** +empties the pane: the script, its results, the count (the next run is Run #1 again) and the +Details window. It asks nothing: the box keeps the focus, so Ctrl+Z (⌘+Z) brings the script back. +It is off with nothing to clear, and while a run is under way. Opening a project (New, Open, the sample, a template, or the same one again), from the app, a script, the assistant or an agent, starts the pane blank: the script, its results, the count and the Details window go with the old project. A script that opens a project itself stays, with its results, as From e72dc789d846c56293ffcf0bd2b173616c72515c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Sat, 7 Nov 2026 16:07:22 -0500 Subject: [PATCH 2/2] docs(ui): Clear's undo needs the box's focus; rename clear_keeping_undo --- crates/ui-egui/src/analysispane.rs | 11 +++++------ docs/user-guide/analysis.md | 5 +++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/ui-egui/src/analysispane.rs b/crates/ui-egui/src/analysispane.rs index 6bb4eead59..9482dacf53 100644 --- a/crates/ui-egui/src/analysispane.rs +++ b/crates/ui-egui/src/analysispane.rs @@ -1572,11 +1572,10 @@ fn start_over_in_another_project(app: &mut RustGisApp) { app.workflow.script_project = Some(opened); } -/// Clear: the pane emptied, as one undo step of the box, which keeps the focus, so its own Ctrl+Z -/// brings the script back at once. The box records undo steps only while it has the focus, so -/// the script is kept as one here, as a suggestion picked keeps the text it replaced -/// (`scriptcomplete::accept`). -fn clear_script_pane(app: &mut RustGisApp, ui: &Ui, box_id: egui::Id) { +/// The Clear button: [`clear_script`], with the script first kept as an undo step of the box and +/// the focus given to the box, so Ctrl+Z brings the script back. The box records undo steps only +/// while focused, so the step is added here, as `scriptcomplete::accept` does. +fn clear_keeping_undo(app: &mut RustGisApp, ui: &Ui, box_id: egui::Id) { use egui::text::{CCursor, CCursorRange}; let mut state = egui::widgets::text_edit::TextEditState::load(ui.ctx(), box_id).unwrap_or_default(); let mut undoer = state.undoer(); @@ -1777,7 +1776,7 @@ fn script(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens, fit: bool) { clear = clear.on_disabled_hover_text(tl!("Wait for the run to finish")); } if clear.clicked() { - clear_script_pane(app, ui, box_id); + clear_keeping_undo(app, ui, box_id); } }); // Above the results' scroll, so it stays in view: its number and how long it took, and on diff --git a/docs/user-guide/analysis.md b/docs/user-guide/analysis.md index 71919eb7a1..45063c4afe 100644 --- a/docs/user-guide/analysis.md +++ b/docs/user-guide/analysis.md @@ -1180,8 +1180,9 @@ mistake shows (Undo takes a whole run back). The results show each line's result Geoprocessing History: each line folded under its command, opening to its result laid out to read, **Copy** for one and **Copy All** for the run, and why it stopped, if it did. **Clear** empties the pane: the script, its results, the count (the next run is Run #1 again) and the -Details window. It asks nothing: the box keeps the focus, so Ctrl+Z (⌘+Z) brings the script back. -It is off with nothing to clear, and while a run is under way. Opening a +Details window. It asks nothing: the box keeps the focus, so Ctrl+Z (⌘+Z) brings the script back; +after a click elsewhere, Ctrl+Z undoes in the project instead, so click into the box first. It is +off with nothing to clear, and while a run is under way. Opening a project (New, Open, the sample, a template, or the same one again), from the app, a script, the assistant or an agent, starts the pane blank: the script, its results, the count and the Details window go with the old project. A script that opens a project itself stays, with its results, as