Toolbars: a rerun of a frame keeps its check budget, and a command that needs a path gets no button

Known::load reset the budget of 12 availability checks on every call, so a
request_discard pass of the same frame asked 12 more. The budget is now
reset only when ctx.cumulative_frame_nr() changes.

ui_listed_on_its_own exempted every params doc starting with {path, which
took in Save Summary... ({path}) and the Scripts folder command
({path: ...}). Both need a path, but ui_command_needs_params returned
false for them, so Save Summary... was offered as a toolbar button and in
Keyboard Shortcuts and ran with empty params. Only the optional {path?
form is exempt now.
This commit is contained in:
dotCooCoo committed 2026-11-22 15:38:37 -08:00
1 parent add7c0f48b
commit 3f6bd6a0e1
2 files changed
+57 -6

No files matched your search

+35 -2
View File
@@ -846,6 +846,8 @@ struct Known {
stale: std::collections::HashMap<String, Option<String>>,
/// How many more commands this frame may ask.
budget: usize,
/// The frame `budget` was set for; a later pass of the same frame keeps what is left of it.
frame: Option<u64>,
/// Is a command still waiting to be asked in this state?
pending: bool,
}
@@ -853,7 +855,8 @@ struct Known {
impl Known {
/// The answers for the state now. The state leaves out a panel shown and a tool chosen, so a
/// frame with a pointer button release or a key press asks every command again, as the Command
/// Palette asks its results again on a click.
/// Palette asks its results again on a click. Every pass of one frame (a `request_discard`
/// rerun) shares that frame's [`ASKS_PER_FRAME`].
fn load(app: &VectorcraftApp, ctx: &egui::Context) -> Known {
let key = crate::palette::availability_key(app);
let mut known = ctx.data(|d| d.get_temp::<Known>(known_id())).unwrap_or_default();
@@ -865,7 +868,11 @@ impl Known {
known.stale.extend(old);
known.key = key;
}
known.budget = ASKS_PER_FRAME;
let frame = ctx.cumulative_frame_nr();
if known.frame != Some(frame) {
known.budget = ASKS_PER_FRAME;
known.frame = Some(frame);
}
known.pending = false;
known
}
@@ -3130,4 +3137,30 @@ mod tests {
assert_eq!(place(&app, "Mine"), (None, false), "released outside its lane");
assert!(ctx.memory(|m| m.area_rect(area_id("Mine"))).unwrap().contains(out));
}
/// A `request_discard` rerun of a frame asks no more commands than are left of that frame's
/// [`ASKS_PER_FRAME`]; the next frame may ask that many again.
#[test]
fn a_rerun_of_a_frame_shares_its_checks() {
let app = app();
let ctx = egui::Context::default();
let mut left = vec![];
for _ in 0..2 {
let mut out = ctx.run_ui(egui::RawInput::default(), |ui| {
let ctx = ui.ctx();
let mut known = Known::load(&app, ctx);
for i in 0..ASKS_PER_FRAME - 2 {
let id = format!("tool:probe-{}-{i}", left.len());
known.why(&app, &id, &id);
}
left.push(known.budget);
ctx.data_mut(|d| d.insert_temp(known_id(), known));
if left.len() == 1 {
ctx.request_discard("a second pass");
}
});
out.textures_delta.clear();
}
assert_eq!(left, [2, 0, 2], "the rerun used what was left; the next frame started anew");
}
}
+22 -4
View File
@@ -1011,11 +1011,12 @@ fn listed_on_its_own(c: &vectorcraft_engine::CommandSpec) -> bool {
/// Is UI command `id` (default key `sc`, params doc `params`) listed in Edit › Keyboard Shortcuts
/// whether or not an item of the menu bar runs it? It is when it has a default key or a params doc
/// of `{}` or `{path…}`. Rename has no default key, and a key press names the selection: it needs
/// no `id`. Color Picker… has no default key either, and a key press opens it for the proxy in
/// front.
/// of `{}` or `{path?…}`, where a call with no path picks a file. A params doc of `{path}` or
/// `{path: …}` (Save Summary…, a Scripts folder script) needs a path, so a key press alone can't
/// run it. Rename has no default key, and a key press names the selection: it needs no `id`. Color
/// Picker… has no default key either, and a key press opens it for the proxy in front.
fn ui_listed_on_its_own(id: &str, sc: &str, params: &str) -> bool {
!sc.is_empty() || params.starts_with("{}") || params.starts_with("{path") || id == "ui.rename" || id == "ui.colorPicker"
!sc.is_empty() || params.starts_with("{}") || params.starts_with("{path?") || id == "ui.rename" || id == "ui.colorPicker"
}
/// Does a menu bar item run the command with no params, so that it does what its label says and opens
@@ -3429,6 +3430,23 @@ mod tests {
assert!(failures.is_empty(), "{failures:#?}");
}
/// A UI command whose params doc starts `{path}` or `{path: …}` needs a path, so it is neither
/// listed on its own nor offered as a button; one that starts `{path?` picks a file without one.
#[test]
fn a_ui_command_that_needs_a_path_is_not_run_without_one() {
for id in ["ui.pdfSummary.save", crate::scripts_menu::COMMAND] {
let (_, _, sc, params) = menus::UI_COMMANDS.iter().find(|c| c.0 == id).unwrap_or_else(|| panic!("{id} is a UI command"));
assert!(!ui_listed_on_its_own(id, sc, params), "{id} is not listed on its own");
assert!(ui_command_needs_params(id), "{id} needs a path");
assert!(!crate::palette::is_command(id), "{id} is not offered as a toolbar button");
}
for id in ["shortcuts.export", "file.open"] {
let (_, _, sc, params) = menus::UI_COMMANDS.iter().find(|c| c.0 == id).unwrap_or_else(|| panic!("{id} is a UI command"));
assert!(ui_listed_on_its_own(id, sc, params) || a_menu_bar_item_runs(id, params), "{id} runs without a path");
assert!(!ui_command_needs_params(id), "{id} picks a file without a path");
}
}
/// #2991: Enter Isolation Mode has no default key but runs on the selection, so it belongs in
/// Edit › Keyboard Shortcuts.
#[test]