From 1e6d200edfc0aaae84b477727c98087da379680a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Tue, 1 Dec 2026 18:21:41 -0500 Subject: [PATCH 1/6] feat(script): move the command help by a grip, and keep where it was left (#3569) --- crates/ui-egui/src/completion.rs | 83 +++++++-- crates/ui-egui/src/exprcomplete.rs | 2 +- crates/ui-egui/src/scriptcomplete.rs | 245 ++++++++++++++++++++++++--- docs/user-guide/analysis.md | 4 +- 4 files changed, 300 insertions(+), 34 deletions(-) diff --git a/crates/ui-egui/src/completion.rs b/crates/ui-egui/src/completion.rs index cfcfdbdc15..a131d2f4fc 100644 --- a/crates/ui-egui/src/completion.rs +++ b/crates/ui-egui/src/completion.rs @@ -33,6 +33,8 @@ const HELP_MIN_WIDTH: f32 = 200.0; pub(crate) const GAP: f32 = 12.0; /// The popup frame's margins, both sides together. pub(crate) const FRAME: f32 = 24.0; +/// The height of the grip over a help that moves (`Tip::show`'s `moved`). +const GRIP: f32 = 10.0; /// What a list offers: the items, and where the word they replace ends (a char index of the /// box's text), which the list goes under. @@ -99,10 +101,11 @@ fn around(anchor: egui::Rect, size: egui::Vec2, screen: egui::Rect, min: f32, si /// size, the part scrolled out of view included, for `place` to choose a side next frame by what /// it holds, not by what last fit (it would stay on a side too short for it). pub(crate) fn popup(ui: &Ui, id: Id, corner: egui::Pos2, room: f32, content: impl FnOnce(&mut Ui)) -> (egui::Rect, egui::Vec2) { - footed(ui, id, corner, room, content, None::) + footed(ui, id, corner, room, content, None::, None::) } -/// `popup`, with a `footer` under its content that stays in view while that scrolls. +/// `popup`, with a `footer` under its content that stays in view while that scrolls, and a +/// `header` over it (the grip that moves it, `grip_bar`). fn footed( ui: &Ui, id: Id, @@ -110,6 +113,7 @@ fn footed( room: f32, content: impl FnOnce(&mut Ui), footer: Option, + header: Option, ) -> (egui::Rect, egui::Vec2) { // A button as tall as the popup's own style draws it (its text and padding), and the gap. let under = footer.as_ref().map_or(0.0, |_| { @@ -117,10 +121,14 @@ fn footed( let s = &style.spacing; (ui.text_style_height(&egui::TextStyle::Button) + 2.0 * s.button_padding.y).max(s.interact_size.y) + s.item_spacing.y }); - let room = (room - under).max(0.0); + let over = header.as_ref().map_or(0.0, |_| GRIP + ui.spacing().item_spacing.y); + let room = (room - under - over).max(0.0); let area = egui::Area::new(id).order(egui::Order::Foreground).fixed_pos(corner).show(ui.ctx(), |ui| { egui::Frame::popup(ui.style()) .show(ui, |ui| { + if let Some(header) = header { + header(ui); + } // The area starts from its last size, so after a short list the scroll area would get // only that room back, scrolling with room to spare: ask for the full height whenever // it scrolls, as Command Search does (#255). Short content still shrinks it to fit. @@ -256,7 +264,9 @@ impl Press { /// where that starts, so it doesn't slide with each key typed. Escape closes it until the cursor /// leaves what it was about (its key, `K`). Help with a short form, with no room beside the /// panel, shows that one, with More under it for the whole help and Less to go back (or -/// Ctrl+Shift+Space for either), until the cursor leaves what it was about. +/// Ctrl+Shift+Space for either), until the cursor leaves what it was about. A box that lets it be +/// moved (`show`'s `moved`) has a grip over it: dragging that moves the help, and a double-click +/// puts it back where it goes by itself. #[derive(Clone)] pub(crate) struct Tip { /// What it shows the help about: what Escape acts on. @@ -267,15 +277,17 @@ pub(crate) struct Tip { size: Option, /// What More showed the whole help of. expanded: Option, - /// With More or Less shown: where the whole popup was drawn and the cursor it was for, to - /// keep it while a press anywhere on it takes the focus from the box. + /// With More, Less or the grip shown: where the whole popup was drawn and the cursor it was + /// for, to keep it while a press anywhere on it takes the focus from the box. popup: Option<(egui::Rect, usize)>, + /// Whether More or Less is shown (the short form, with no room beside the pane). + shortened: bool, press: Press, } impl Default for Tip { fn default() -> Self { - Self { shown: None, dismissed: None, size: None, expanded: None, popup: None, press: Press::default() } + Self { shown: None, dismissed: None, size: None, expanded: None, popup: None, shortened: false, press: Press::default() } } } @@ -300,7 +312,11 @@ impl Tip { /// (`Asked::keys`), which takes the key with Shift down too. pub fn toggle_keys(&mut self, ui: &Ui, id: Id) -> bool { let shortcut = Modifiers::CTRL | Modifiers::SHIFT; - if self.popup.is_none() || !ui.memory(|m| m.has_focus(id)) || !ui.input_mut(|i| i.consume_key(shortcut, Key::Space)) { + if !self.shortened + || self.popup.is_none() + || !ui.memory(|m| m.has_focus(id)) + || !ui.input_mut(|i| i.consume_key(shortcut, Key::Space)) + { return false; } self.toggle(); @@ -316,6 +332,7 @@ impl Tip { fn gone(&mut self) { self.size = None; self.popup = None; + self.shortened = false; self.press = Press::default(); } @@ -353,7 +370,9 @@ impl Tip { /// false only when it has a `short` form and no room beside the pane), `rows` monospace lines /// high at first guess; beside `pane` (the panel the box is in) with room there, else on side `side` /// of the cursor's line when it fits there. Not with the cursor out of the box's view - /// (`visible`) or what Escape closed. + /// (`visible`) or what Escape closed. With `moved` (a box whose help may be moved), a grip + /// over it: dragged, it leaves the corner there, which every help drawn with the same `moved` + /// takes (kept on the screen); double-clicked, it clears it. pub fn show( &mut self, ui: &Ui, @@ -366,6 +385,7 @@ impl Tip { side: Side, pane: Option, short: bool, + moved: Option<&mut Option>, draw: impl FnOnce(&mut Ui, f32, bool), ) { // Out of what Escape closed (in nothing, or straight into something else), it may show @@ -404,13 +424,40 @@ impl Tip { let (corner, room) = place(anchor, size, screen, row * 3.0, side); (corner, width, room) }); + // Where it was left, as far as the screen holds it (its size last frame): the width it + // takes anywhere, and the room under its corner. + let (corner, width, room) = match moved.as_deref().copied().flatten() { + Some(left) => { + let kept = egui::pos2( + left.x.min(screen.right() - size.x).max(screen.left()), + left.y.min(screen.bottom() - size.y).max(screen.top()), + ); + (kept, (screen.width() - FRAME).clamp(0.0, HELP_WIDTH), (screen.bottom() - kept.y - FRAME).max(row * 3.0)) + } + None => (corner, width, room), + }; let mut pressed = false; let footer = shortened.then_some(|ui: &mut Ui| { let label = if whole { tl!("Less") } else { tl!("More") }; pressed = ui.button(label).on_hover_text(tl!("Ctrl+Shift+Space")).clicked(); }); - let (rect, drawn) = footed(ui, id, corner, room, |ui| draw(ui, width, whole), footer); - match at.filter(|_| shortened) { + let mut grip = None; + let header = moved.is_some().then_some(|ui: &mut Ui| grip = Some(grip_bar(ui, width))); + let (rect, drawn) = footed(ui, id, corner, room, |ui| draw(ui, width, whole), footer, header); + if let (Some(grip), Some(moved)) = (&grip, moved) { + if grip.double_clicked() { + *moved = None; + ui.ctx().request_repaint(); + } else if grip.dragged() && grip.drag_delta() != egui::Vec2::ZERO { + // Only while it moves: held still, nothing changes and nothing repaints. It adds to + // where it was left, not to where the screen let it be, so it comes back with the + // pointer after going past an edge. + *moved = Some(moved.unwrap_or(corner) + grip.drag_delta()); + ui.ctx().request_repaint(); + } + } + self.shortened = shortened; + match at.filter(|_| shortened || grip.is_some()) { Some(at) => { let on = ui.input(|i| i.pointer.interact_pos().is_some_and(|p| rect.contains(p))); self.press.give_back(ui, on, out.response.response.id); @@ -436,6 +483,20 @@ impl Tip { } } +/// The grip over a help that moves, `width` wide: dragging it moves the help, a double-click puts +/// it back. A button for a screen reader; the pointer shows a hand over it. +fn grip_bar(ui: &mut Ui, width: f32) -> egui::Response { + let (rect, resp) = ui.allocate_exact_size(egui::vec2(width, GRIP), egui::Sense::click_and_drag()); + resp.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, true, tl!("Move the help"))); + let visuals = ui.visuals(); + let colour = if resp.hovered() || resp.dragged() { visuals.text_color() } else { visuals.weak_text_color() }; + ui.painter().rect_filled(egui::Rect::from_center_size(rect.center(), egui::vec2(24.0, 3.0)), 1.5, colour); + if resp.dragged() { + ui.ctx().set_cursor_icon(egui::CursorIcon::Grabbing); + } + resp.on_hover_cursor(egui::CursorIcon::Grab).on_hover_text(tl!("Drag to move it. Double-click to put it back.")) +} + /// Where Ctrl+Space asked a box for its list (the text's hash and the cursor): the list shows /// there with nothing typed, until the text or the cursor moves on. #[derive(Clone, Default)] diff --git a/crates/ui-egui/src/exprcomplete.rs b/crates/ui-egui/src/exprcomplete.rs index b12d65b1ea..31d57557aa 100644 --- a/crates/ui-egui/src/exprcomplete.rs +++ b/crates/ui-egui/src/exprcomplete.rs @@ -403,7 +403,7 @@ pub(crate) fn expr_edit_lines( let at = cursor.filter(|_| !state.list.is_open()); // Kept by its `(`, and anchored there; over the line, as under the box are its error and help. let about = call.map(|c| (c.open, c.open)); - state.tip.show(ui, id.with("expr_tip"), &out, visible, at, about, TIP_ROWS, Side::Above, None, false, |ui, width, _| { + state.tip.show(ui, id.with("expr_tip"), &out, visible, at, about, TIP_ROWS, Side::Above, None, false, None, |ui, width, _| { if let Some(call) = &call { draw_call(ui, call, width); } diff --git a/crates/ui-egui/src/scriptcomplete.rs b/crates/ui-egui/src/scriptcomplete.rs index 133bc1a109..72bbd807ea 100644 --- a/crates/ui-egui/src/scriptcomplete.rs +++ b/crates/ui-egui/src/scriptcomplete.rs @@ -1475,6 +1475,9 @@ struct HintState { /// char index of the script). Each has what Escape closed of its own: closing one doesn't /// close the other, and going through a call doesn't bring back a command's help closed. call: Tip, + /// Where the user left the help by dragging its grip, for both: the corner it takes until a + /// double-click on the grip clears it. Kept while the app is open, not saved. + moved: Option, /// What it was worked out to show, for which cursor, script (its hash), language (the help is /// translated), plugins' revision (a plugin's command comes and goes with its plugin) and /// project (the session's revision and active layer: the fields an expression is read over): @@ -1693,23 +1696,50 @@ pub fn hint(ui: &Ui, box_id: Id, out: &TextEditOutput, visible: egui::Rect, scri // With nothing to leave out, there is no short form. let short = help.as_ref().is_some_and(|(_, help, _)| !help.params.is_empty()); let id = box_id.with("complete_hint"); - state.hint.tip.show(ui, id, out, visible, at, about, rows, Side::Below, pane, short, |ui, width, whole| { - if let Some((_, help, param)) = &help { - if whole { - draw_help(ui, help, width); - } else { - draw_short(ui, help, *param, width); + state.hint.tip.show( + ui, + id, + out, + visible, + at, + about, + rows, + Side::Below, + pane, + short, + Some(&mut state.hint.moved), + |ui, width, whole| { + if let Some((_, help, param)) = &help { + if whole { + draw_help(ui, help, width); + } else { + draw_short(ui, help, *param, width); + } } - } - }); + }, + ); } let about = call.as_ref().map(|(open, _)| (*open, *open)); let rows = crate::exprcomplete::TIP_ROWS; - state.hint.call.show(ui, box_id.with("complete_call"), out, visible, at, about, rows, Side::Below, pane, false, |ui, width, _| { - if let Some((_, call)) = &call { - crate::exprcomplete::draw_call(ui, call, width); - } - }); + let moved = Some(&mut state.hint.moved); + state.hint.call.show( + ui, + box_id.with("complete_call"), + out, + visible, + at, + about, + rows, + Side::Below, + pane, + false, + moved, + |ui, width, _| { + if let Some((_, call)) = &call { + crate::exprcomplete::draw_call(ui, call, width); + } + }, + ); store(ui, box_id, state); } @@ -2961,14 +2991,20 @@ mod tests { /// The Script pane docked at a side of a wide window, `typed` into its box. fn docked(left: bool, typed: &str) -> egui_kittest::Harness<'static, crate::RustGisApp> { + docked_stepping(left, typed, 0.25) + } + + /// `docked`, each frame `dt` seconds long (kittest's default 0.25). + fn docked_stepping(left: bool, typed: &str, dt: f32) -> egui_kittest::Harness<'static, crate::RustGisApp> { use egui_kittest::kittest::Queryable; - let mut h = egui_kittest::Harness::builder().allow_missing_glyphs().with_size(egui::vec2(1200.0, 700.0)).build_ui_state( - move |ui, app: &mut crate::RustGisApp| { - let panel = if left { egui::Panel::left("script_side") } else { egui::Panel::right("script_side") }; - panel.exact_size(400.0).show(ui, |ui| crate::analysispane::script_pane(app, ui, &crate::theme::Tokens::light())); - }, - crate::RustGisApp::with_sample(), - ); + let mut h = + egui_kittest::Harness::builder().allow_missing_glyphs().with_size(egui::vec2(1200.0, 700.0)).with_step_dt(dt).build_ui_state( + move |ui, app: &mut crate::RustGisApp| { + let panel = if left { egui::Panel::left("script_side") } else { egui::Panel::right("script_side") }; + panel.exact_size(400.0).show(ui, |ui| crate::analysispane::script_pane(app, ui, &crate::theme::Tokens::light())); + }, + crate::RustGisApp::with_sample(), + ); h.run(); h.get_by_role(egui::accesskit::Role::MultilineTextInput).focus(); h.run(); @@ -2992,7 +3028,9 @@ mod tests { let clear = if left { sig.min.x > script.max.x } else { sig.max.x < script.min.x }; assert!(clear, "left {left}, {id}: beside the pane: {sig:?} {script:?}"); if id == "map.goToXY" { - assert!((sig.min.y - script.min.y).abs() < 20.0, "left {left}: level with the line: {sig:?} {script:?}"); + // The grip is the help's top; the signature sits under it. + let top = grip(&h).min.y; + assert!((top - script.min.y).abs() < 20.0, "left {left}: level with the line: {top} {script:?}"); // Typed on until the line wraps: the help stays where it was. type_in(&mut h, r#""lon": 2.35, "lat": 48.85, "scale": 5000000, "name": "long enough to wrap", "#); let on = h.get_by_label(&label).rect(); @@ -3054,6 +3092,171 @@ mod tests { } } + /// The grip at the top of the help, which moves it (#3569). + const GRIP_LABEL: &str = "Move the help"; + + fn grip(h: &egui_kittest::Harness<'static, crate::RustGisApp>) -> egui::Rect { + use egui_kittest::kittest::Queryable; + h.get_by_role_and_label(egui::accesskit::Role::Button, GRIP_LABEL).rect() + } + + /// Presses the grip, moves the pointer by `by` in a few frames and lets go, as a hand does. + fn drag_grip(h: &mut egui_kittest::Harness<'static, crate::RustGisApp>, by: egui::Vec2) { + let from = grip(h).center(); + h.event(egui::Event::PointerMoved(from)); + h.run(); + h.event(egui::Event::PointerButton { + pos: from, + button: egui::PointerButton::Primary, + pressed: true, + modifiers: Default::default(), + }); + h.run(); + for step in 1..=4 { + h.event(egui::Event::PointerMoved(from + by * (step as f32 / 4.0))); + h.run(); + } + h.event(egui::Event::PointerButton { + pos: from + by, + button: egui::PointerButton::Primary, + pressed: false, + modifiers: Default::default(), + }); + h.run(); + } + + /// A command's signature as drawn, where its help is. + fn signature(h: &egui_kittest::Harness<'static, crate::RustGisApp>, id: &str) -> egui::Rect { + use egui_kittest::kittest::Queryable; + let help = super::help(&h.state().session, id).unwrap(); + h.get_by_label(&format!("{}{}", help.id, help.keys)).rect() + } + + /// Dragging the grip at the top of the help moves it as far as the pointer went, and the + /// script keeps the focus and what is typed goes on into it (#3569). + #[test] + fn dragging_the_grip_moves_the_help() { + let mut h = docked(false, "map.goToXY {"); + let before = signature(&h, "map.goToXY"); + drag_grip(&mut h, egui::vec2(-150.0, 100.0)); + let after = signature(&h, "map.goToXY"); + assert!(((after.min - before.min) - egui::vec2(-150.0, 100.0)).length() < 1.5, "moved by the drag: {before:?} {after:?}"); + type_in(&mut h, r#""lon": 2"#); + assert!(h.state().workflow.script.ends_with(r#""lon": 2"#), "the script kept the focus: {:?}", h.state().workflow.script); + assert!((signature(&h, "map.goToXY").min - after.min).length() < 0.5, "typing didn't move it back"); + } + + /// A moved help stays where it was left for the next ones, too: after Escape, in another + /// command's braces, and for a function's signature (#3569). + #[test] + fn a_moved_help_shows_where_it_was_left() { + use egui_kittest::kittest::Queryable; + let mut h = docked(false, "map.goToXY {"); + drag_grip(&mut h, egui::vec2(-150.0, 100.0)); + let left = signature(&h, "map.goToXY").min; + // Escape closes it; out of the braces and into another command's, it shows there again. + h.key_press(egui::Key::Escape); + h.run(); + assert!(h.query_by_role_and_label(egui::accesskit::Role::Button, GRIP_LABEL).is_none(), "closed"); + type_in(&mut h, "}\nmap.goToXY {"); + assert!((signature(&h, "map.goToXY").min - left).length() < 1.5, "another command: where it was left"); + // A function's signature in an expression, in place of its command's help. + type_in(&mut h, r#""kind": "x"}"#); + type_in(&mut h, "\nselect.byAttributes {\"layer\": \"Countries\", \"where\": \"round(pop_est, "); + let call = h.get_by_role_and_label(egui::accesskit::Role::Label, "round(x[, places])").rect(); + assert!((call.min - left).length() < 1.5, "a signature: {call:?} {left:?}"); + } + + /// A double-click on the grip puts the help back where it goes by itself, for the next ones too. + #[test] + fn double_clicking_the_grip_puts_the_help_back() { + // A short frame, so two clicks one frame apart are a double-click (egui's window for it is + // 0.3 s). + let mut h = docked_stepping(false, "map.goToXY {", 0.05); + let first = signature(&h, "map.goToXY"); + drag_grip(&mut h, egui::vec2(-150.0, 100.0)); + assert!((signature(&h, "map.goToXY").min - first.min).length() > 50.0, "moved"); + let at = grip(&h).center(); + h.event(egui::Event::PointerMoved(at)); + h.run(); + // Two clicks one frame apart (a step each, not `run`, which spends several: egui's + // double-click window is 0.3 s). + for pressed in [true, false, true, false] { + h.event(egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() }); + h.step(); + } + h.run(); + assert!((signature(&h, "map.goToXY").min - first.min).length() < 1.5, "back where it was"); + type_in(&mut h, r#""lon": 2"#); + assert!((signature(&h, "map.goToXY").min - first.min).length() < 1.5, "and it stays there"); + } + + /// A click on the grip, with no drag, moves nothing and leaves the focus in the script. + #[test] + fn clicking_the_grip_moves_nothing() { + let mut h = docked(false, "map.goToXY {"); + let before = signature(&h, "map.goToXY"); + press(&mut h, GRIP_LABEL); + assert!((signature(&h, "map.goToXY").min - before.min).length() < 0.5, "didn't move"); + type_in(&mut h, r#""lon": 2"#); + assert!(h.state().workflow.script.ends_with(r#""lon": 2"#), "the script kept the focus: {:?}", h.state().workflow.script); + } + + /// With no room beside the pane, the short help moves too, and More still shows the whole one, + /// where it is. + #[test] + fn the_short_help_moves_and_expands_in_place() { + use egui_kittest::kittest::Queryable; + let mut h = pane(); + type_in(&mut h, "map.goToXY {"); + let before = signature(&h, "map.goToXY"); + drag_grip(&mut h, egui::vec2(-20.0, 60.0)); + let moved = signature(&h, "map.goToXY"); + assert!(((moved.min - before.min) - egui::vec2(-20.0, 60.0)).length() < 1.5, "moved: {before:?} {moved:?}"); + assert!(button(&h, "More"), "still short"); + press(&mut h, "More"); + let help = super::help(&h.state().session, "map.goToXY").unwrap(); + h.get_by_label(&help.label); + assert!((signature(&h, "map.goToXY").min - moved.min).length() < 1.5, "whole, in the same place"); + } + + /// Dragged past the screen's edge, the whole help stays on the screen, and dragged back it + /// follows the pointer from where it was left, not from the edge it stopped at. + #[test] + fn a_help_dragged_off_the_screen_stays_on_it() { + let mut h = docked(false, "map.goToXY {"); + let start = signature(&h, "map.goToXY"); + drag_grip(&mut h, egui::vec2(5000.0, 5000.0)); + let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1200.0, 700.0)); + let sig = signature(&h, "map.goToXY"); + assert!(screen.contains_rect(sig), "inside the screen: {sig:?}"); + drag_grip(&mut h, egui::vec2(-5000.0, -5000.0)); + assert!((signature(&h, "map.goToXY").min - start.min).length() < 1.5, "back where it started"); + } + + /// A window too narrow for a moved help holds it on the screen; widened again, it is back + /// where it was left. + #[test] + fn a_moved_help_comes_back_when_the_window_widens() { + let mut h = docked(false, "map.goToXY {"); + drag_grip(&mut h, egui::vec2(300.0, 0.0)); + let left = signature(&h, "map.goToXY").min; + h.set_size(egui::vec2(800.0, 700.0)); + h.run(); + assert!(signature(&h, "map.goToXY").max.x <= 800.5, "inside the narrow window"); + h.set_size(egui::vec2(1200.0, 700.0)); + h.run(); + assert!((signature(&h, "map.goToXY").min - left).length() < 1.5, "back where it was left"); + } + + /// The expression boxes outside the Script pane have no grip: their help is not moved. + #[test] + fn no_grip_without_a_script_help() { + use egui_kittest::kittest::Queryable; + let h = docked(false, ""); + assert!(h.query_by_role_and_label(egui::accesskit::Role::Button, GRIP_LABEL).is_none(), "no help, no grip"); + } + /// With no room beside the pane, a command's help is short: its signature and More, with the /// parameter the cursor is in once it's in one (#3535). #[test] diff --git a/docs/user-guide/analysis.md b/docs/user-guide/analysis.md index f1ed9bab37..3a360b3082 100644 --- a/docs/user-guide/analysis.md +++ b/docs/user-guide/analysis.md @@ -1911,7 +1911,9 @@ help shows beside the Script pane, level with the line, so the script stays in v either side it shows by the cursor, short: the signature, cut off past two lines, and the parameter the cursor is in, with **More** for the whole help and **Less** to go back (Ctrl+Shift+Space does either; on macOS too it is the Ctrl key); a command with no parameters keeps its whole help, with -no button. Escape closes it. A quote that starts a key in a command's +no button. Escape closes it. If the help is in the way, drag the grip at its top to move it: it +shows there from then on, until you close the app, and a double-click on the grip puts it back +where it goes by itself. A quote that starts a key in a command's braces opens the list of its keys not given yet, beside the highlighted key's description; accepting one closes it with its colon (`"size": `). The same goes in a key's own object, or in each object of its list, for the keys the From 8300a495536f9dba2ba4059a42b566e32ff4ba67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Tue, 1 Dec 2026 19:21:46 -0500 Subject: [PATCH 2/6] test(script): pin the moved help's widening and a press on the whole help (#3569) --- crates/ui-egui/src/scriptcomplete.rs | 31 +++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/scriptcomplete.rs b/crates/ui-egui/src/scriptcomplete.rs index 72bbd807ea..8e0bd23bf2 100644 --- a/crates/ui-egui/src/scriptcomplete.rs +++ b/crates/ui-egui/src/scriptcomplete.rs @@ -3239,14 +3239,39 @@ mod tests { #[test] fn a_moved_help_comes_back_when_the_window_widens() { let mut h = docked(false, "map.goToXY {"); + let start = signature(&h, "map.goToXY"); drag_grip(&mut h, egui::vec2(300.0, 0.0)); - let left = signature(&h, "map.goToXY").min; + let left = signature(&h, "map.goToXY"); + // Moved the whole way, and short of the screen's right edge, so it was left where the + // pointer put it and not where the edge holds it. + assert!(((left.min - start.min) - egui::vec2(300.0, 0.0)).length() < 1.5, "moved: {start:?} {left:?}"); + assert!(left.max.x < 1200.0 - 8.0, "short of the edge: {left:?}"); h.set_size(egui::vec2(800.0, 700.0)); h.run(); - assert!(signature(&h, "map.goToXY").max.x <= 800.5, "inside the narrow window"); + let narrow = signature(&h, "map.goToXY"); + assert!(narrow.max.x <= 800.5 && narrow.min.x < left.min.x - 50.0, "held inside the narrow window: {narrow:?}"); h.set_size(egui::vec2(1200.0, 700.0)); h.run(); - assert!((signature(&h, "map.goToXY").min - left).length() < 1.5, "back where it was left"); + assert!((signature(&h, "map.goToXY").min - left.min).length() < 1.5, "back where it was left"); + } + + /// A press on the body of the whole help (not on its grip or a button) keeps it open and gives + /// the focus back to the script box, as it does for the short help's buttons: with the grip, + /// every help is pressed to be dragged (#3569). + #[test] + fn a_press_on_the_whole_help_keeps_it_and_the_focus() { + let mut h = docked(false, "map.goToXY {"); + let at = signature(&h, "map.goToXY").center(); + h.event(egui::Event::PointerMoved(at)); + h.run(); + for pressed in [true, false] { + h.event(egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() }); + h.run(); + } + signature(&h, "map.goToXY"); + type_in(&mut h, r#""lon": 2"#); + assert!(h.state().workflow.script.ends_with(r#""lon": 2"#), "the box got the focus back: {:?}", h.state().workflow.script); + signature(&h, "map.goToXY"); } /// The expression boxes outside the Script pane have no grip: their help is not moved. From 02a3d11d00ee6effdb9cdac5d95baee224d6b46d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Tue, 1 Dec 2026 19:30:03 -0500 Subject: [PATCH 3/6] test(script): explicit help assertions, a doc that says what it checks, an overhang guard (#3569) --- crates/ui-egui/src/scriptcomplete.rs | 32 +++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/scriptcomplete.rs b/crates/ui-egui/src/scriptcomplete.rs index 8e0bd23bf2..9f1d3baf31 100644 --- a/crates/ui-egui/src/scriptcomplete.rs +++ b/crates/ui-egui/src/scriptcomplete.rs @@ -3268,13 +3268,39 @@ mod tests { h.event(egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() }); h.run(); } - signature(&h, "map.goToXY"); + assert!(signature(&h, "map.goToXY").width() > 0.0, "the help is still there"); type_in(&mut h, r#""lon": 2"#); assert!(h.state().workflow.script.ends_with(r#""lon": 2"#), "the box got the focus back: {:?}", h.state().workflow.script); - signature(&h, "map.goToXY"); + assert!(signature(&h, "map.goToXY").width() > 0.0, "and it stays"); } - /// The expression boxes outside the Script pane have no grip: their help is not moved. + /// A help placed beside a narrow pane is narrower than a moved one (which takes the width the + /// window gives it): the first frames of a drag are held on the screen for the width it is + /// drawn at now, not for last frame's, so it never overhangs the edge. + #[test] + fn a_help_moved_from_beside_a_narrow_pane_never_overhangs() { + let mut h = docked(false, "map.goToXY {"); + h.set_size(egui::vec2(700.0, 700.0)); + h.run(); + let from = grip(&h).center(); + h.event(egui::Event::PointerMoved(from)); + h.run(); + h.event(egui::Event::PointerButton { + pos: from, + button: egui::PointerButton::Primary, + pressed: true, + modifiers: Default::default(), + }); + h.run(); + for step in 1..=6 { + h.event(egui::Event::PointerMoved(from + egui::vec2(60.0 * step as f32, 0.0))); + h.step(); + let sig = signature(&h, "map.goToXY"); + assert!(sig.max.x <= 700.5, "step {step}: inside the window: {sig:?}"); + } + } + + /// With nothing in a command's braces there is no help in the Script box, so no grip. #[test] fn no_grip_without_a_script_help() { use egui_kittest::kittest::Queryable; From 69460bc698c7bda7c2d2eac1c673789cc99660bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Tue, 1 Dec 2026 19:37:49 -0500 Subject: [PATCH 4/6] test(script): assert on the grip, and a field doc that says what it holds (#3569) --- crates/ui-egui/src/completion.rs | 2 +- crates/ui-egui/src/scriptcomplete.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/completion.rs b/crates/ui-egui/src/completion.rs index a131d2f4fc..2b38481e1b 100644 --- a/crates/ui-egui/src/completion.rs +++ b/crates/ui-egui/src/completion.rs @@ -280,7 +280,7 @@ pub(crate) struct Tip { /// With More, Less or the grip shown: where the whole popup was drawn and the cursor it was /// for, to keep it while a press anywhere on it takes the focus from the box. popup: Option<(egui::Rect, usize)>, - /// Whether More or Less is shown (the short form, with no room beside the pane). + /// Whether the short form is shown (with no room beside the pane), so More or Less with it. shortened: bool, press: Press, } diff --git a/crates/ui-egui/src/scriptcomplete.rs b/crates/ui-egui/src/scriptcomplete.rs index 9f1d3baf31..457e30c008 100644 --- a/crates/ui-egui/src/scriptcomplete.rs +++ b/crates/ui-egui/src/scriptcomplete.rs @@ -3268,10 +3268,10 @@ mod tests { h.event(egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() }); h.run(); } - assert!(signature(&h, "map.goToXY").width() > 0.0, "the help is still there"); + assert!(grip(&h).height() > 0.0, "the help, with its grip, is still there"); type_in(&mut h, r#""lon": 2"#); assert!(h.state().workflow.script.ends_with(r#""lon": 2"#), "the box got the focus back: {:?}", h.state().workflow.script); - assert!(signature(&h, "map.goToXY").width() > 0.0, "and it stays"); + assert!(grip(&h).height() > 0.0, "and it stays"); } /// A help placed beside a narrow pane is narrower than a moved one (which takes the width the From 24a4cf75d7da89563f56827a8729050d95c26b68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Tue, 1 Dec 2026 19:43:49 -0500 Subject: [PATCH 5/6] fix(script): keep a function's signature help when its grip is pressed, and hold a moved help on the screen for its drawn width (#3569) --- crates/ui-egui/src/completion.rs | 10 +++++--- crates/ui-egui/src/scriptcomplete.rs | 35 +++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/crates/ui-egui/src/completion.rs b/crates/ui-egui/src/completion.rs index 2b38481e1b..43f332644c 100644 --- a/crates/ui-egui/src/completion.rs +++ b/crates/ui-egui/src/completion.rs @@ -297,8 +297,8 @@ impl Tip { self.shown.is_some() } - /// The cursor the help is kept for while its More or Less is pressed: the box may have no - /// focus then, nor a cursor of its own. + /// The cursor the help is kept for while its More, Less or grip is pressed: the box may have + /// no focus then, nor a cursor of its own. pub fn held(&self, ui: &Ui) -> Option { let (rect, at) = self.popup?; ui.input(|i| { @@ -428,11 +428,15 @@ impl Tip { // takes anywhere, and the room under its corner. let (corner, width, room) = match moved.as_deref().copied().flatten() { Some(left) => { + // Held on the screen for the width it is drawn at now, not last frame's: a help that + // was beside a narrow pane was narrower than a moved one is. + let moved_width = (screen.width() - FRAME).clamp(0.0, HELP_WIDTH); + let size = egui::vec2(size.x.max(moved_width + FRAME), size.y); let kept = egui::pos2( left.x.min(screen.right() - size.x).max(screen.left()), left.y.min(screen.bottom() - size.y).max(screen.top()), ); - (kept, (screen.width() - FRAME).clamp(0.0, HELP_WIDTH), (screen.bottom() - kept.y - FRAME).max(row * 3.0)) + (kept, moved_width, (screen.bottom() - kept.y - FRAME).max(row * 3.0)) } None => (corner, width, room), }; diff --git a/crates/ui-egui/src/scriptcomplete.rs b/crates/ui-egui/src/scriptcomplete.rs index 457e30c008..ffa5fd8331 100644 --- a/crates/ui-egui/src/scriptcomplete.rs +++ b/crates/ui-egui/src/scriptcomplete.rs @@ -1653,8 +1653,9 @@ pub fn hint(ui: &Ui, box_id: Id, out: &TextEditOutput, visible: egui::Rect, scri let mut state = load(ui, box_id); let focused = out.response.response.has_focus() && ui.input(|i| i.focused); let cursor = out.cursor_range.filter(|r| focused && !state.list.is_open() && r.is_empty()).map(|r| r.primary.index.0); - // While More or Less is pressed, the cursor it was shown for. - let at = state.hint.tip.held(ui).or(cursor); + // While More, Less or a grip is pressed, the cursor the help was shown for (a command's or a + // function's: only one of them is shown). + let at = state.hint.tip.held(ui).or_else(|| state.hint.call.held(ui)).or(cursor); // Its own hash of the script, not the list's: it mustn't depend on how `show` ran this frame. let text = egui::util::hash(script); // The help is translated, a plugin's command comes and goes with its plugin, and an @@ -3279,7 +3280,7 @@ mod tests { /// drawn at now, not for last frame's, so it never overhangs the edge. #[test] fn a_help_moved_from_beside_a_narrow_pane_never_overhangs() { - let mut h = docked(false, "map.goToXY {"); + let mut h = docked(true, "map.goToXY {"); h.set_size(egui::vec2(700.0, 700.0)); h.run(); let from = grip(&h).center(); @@ -3300,6 +3301,34 @@ mod tests { } } + /// A function's signature has the grip too, and a click or a double-click on it keeps the + /// signature open and the script's focus, as for a command's help: the box gives the focus up + /// on the press, and the signature is kept by its own tip (#3569). + #[test] + fn a_calls_signature_keeps_its_help_when_its_grip_is_clicked() { + use egui_kittest::kittest::Queryable; + let mut h = docked_stepping(false, r#"select.byAttributes {"layer": "Countries", "where": "round(pop_est, "#, 0.05); + let sig = |h: &egui_kittest::Harness<'static, crate::RustGisApp>| { + h.get_by_role_and_label(egui::accesskit::Role::Label, "round(x[, places])").rect() + }; + sig(&h); + press(&mut h, GRIP_LABEL); + sig(&h); + type_in(&mut h, "2"); + assert!(h.state().workflow.script.ends_with("pop_est, 2"), "the box got the focus back: {:?}", h.state().workflow.script); + sig(&h); + // A double-click: the help goes back to where it goes by itself, and stays. + let at = grip(&h).center(); + for pressed in [true, false, true, false] { + h.event(egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() }); + h.step(); + } + h.run(); + sig(&h); + type_in(&mut h, "3"); + assert!(h.state().workflow.script.ends_with("pop_est, 23"), "and still typing: {:?}", h.state().workflow.script); + } + /// With nothing in a command's braces there is no help in the Script box, so no grip. #[test] fn no_grip_without_a_script_help() { From 9e69f9200cec07660bd30fb6bf8cec7e3f54f9de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Tue, 1 Dec 2026 21:49:43 -0500 Subject: [PATCH 6/6] refactor(script): name the grip's position pos, read the popup's spacing once, and say what the chord does with only a grip (#3569) --- crates/ui-egui/src/completion.rs | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/crates/ui-egui/src/completion.rs b/crates/ui-egui/src/completion.rs index 43f332644c..117646d63e 100644 --- a/crates/ui-egui/src/completion.rs +++ b/crates/ui-egui/src/completion.rs @@ -115,13 +115,14 @@ fn footed( footer: Option, header: Option, ) -> (egui::Rect, egui::Vec2) { - // A button as tall as the popup's own style draws it (its text and padding), and the gap. + // The popup's own style, for the room the footer and the header take. + let style = ui.ctx().global_style(); + let s = &style.spacing; + // A button as tall as that style draws it (its text and padding), and the gap. let under = footer.as_ref().map_or(0.0, |_| { - let style = ui.ctx().global_style(); - let s = &style.spacing; (ui.text_style_height(&egui::TextStyle::Button) + 2.0 * s.button_padding.y).max(s.interact_size.y) + s.item_spacing.y }); - let over = header.as_ref().map_or(0.0, |_| GRIP + ui.spacing().item_spacing.y); + let over = header.as_ref().map_or(0.0, |_| GRIP + s.item_spacing.y); let room = (room - under - over).max(0.0); let area = egui::Area::new(id).order(egui::Order::Foreground).fixed_pos(corner).show(ui.ctx(), |ui| { egui::Frame::popup(ui.style()) @@ -309,7 +310,8 @@ impl Tip { /// Before the box (its id `id`) sees the keys, with More or Less shown and the box focused: /// Ctrl+Shift+Space does what that button does. Whether it did. Read before Ctrl+Space - /// (`Asked::keys`), which takes the key with Shift down too. + /// (`Asked::keys`), which takes the key with Shift down too: with a help that has no More or + /// Less (the whole help, with only its grip), it's left to Ctrl+Space, as it always was. pub fn toggle_keys(&mut self, ui: &Ui, id: Id) -> bool { let shortcut = Modifiers::CTRL | Modifiers::SHIFT; if !self.shortened @@ -412,8 +414,8 @@ impl Tip { }; let row = ui.text_style_height(&egui::TextStyle::Monospace) + ui.spacing().item_spacing.y + 4.0; let screen = ui.ctx().content_rect(); - let width = (screen.width() - FRAME).clamp(0.0, HELP_WIDTH); - let size = self.size.unwrap_or(egui::vec2(width + FRAME, row * rows as f32)); + let full_width = (screen.width() - FRAME).clamp(0.0, HELP_WIDTH); + let size = self.size.unwrap_or(egui::vec2(full_width + FRAME, row * rows as f32)); // Beside the pane it's level with the line `start` is on, which stays put as the cursor // moves down a wrapped line; with that line scrolled out over the box, with the box's top. let level = start.translate(egui::vec2(0.0, (visible.top() - start.top()).max(0.0))); @@ -422,7 +424,7 @@ impl Tip { let whole = !shortened || self.expanded.as_ref() == Some(&k); let (corner, width, room) = placed.unwrap_or_else(|| { let (corner, room) = place(anchor, size, screen, row * 3.0, side); - (corner, width, room) + (corner, full_width, room) }); // Where it was left, as far as the screen holds it (its size last frame): the width it // takes anywhere, and the room under its corner. @@ -430,13 +432,12 @@ impl Tip { Some(left) => { // Held on the screen for the width it is drawn at now, not last frame's: a help that // was beside a narrow pane was narrower than a moved one is. - let moved_width = (screen.width() - FRAME).clamp(0.0, HELP_WIDTH); - let size = egui::vec2(size.x.max(moved_width + FRAME), size.y); + let size = egui::vec2(size.x.max(full_width + FRAME), size.y); let kept = egui::pos2( left.x.min(screen.right() - size.x).max(screen.left()), left.y.min(screen.bottom() - size.y).max(screen.top()), ); - (kept, moved_width, (screen.bottom() - kept.y - FRAME).max(row * 3.0)) + (kept, full_width, (screen.bottom() - kept.y - FRAME).max(row * 3.0)) } None => (corner, width, room), }; @@ -448,15 +449,15 @@ impl Tip { let mut grip = None; let header = moved.is_some().then_some(|ui: &mut Ui| grip = Some(grip_bar(ui, width))); let (rect, drawn) = footed(ui, id, corner, room, |ui| draw(ui, width, whole), footer, header); - if let (Some(grip), Some(moved)) = (&grip, moved) { + if let (Some(grip), Some(pos)) = (&grip, moved) { if grip.double_clicked() { - *moved = None; + *pos = None; ui.ctx().request_repaint(); } else if grip.dragged() && grip.drag_delta() != egui::Vec2::ZERO { // Only while it moves: held still, nothing changes and nothing repaints. It adds to // where it was left, not to where the screen let it be, so it comes back with the // pointer after going past an edge. - *moved = Some(moved.unwrap_or(corner) + grip.drag_delta()); + *pos = Some(pos.unwrap_or(corner) + grip.drag_delta()); ui.ctx().request_repaint(); } }