From 818ed8823bf854c11fcebd94b4fee3459731e36a Mon Sep 17 00:00:00 2001 From: David Mann Date: Tue, 17 Nov 2026 20:18:15 +0100 Subject: [PATCH 01/10] perf(ui): build the toolbar's slots once per layout, look up bridged commands without allocating (#15493) Since the port to the craft UI framework the UI pass costs about ten times the release's. A profile of a menu hover showed two PhotoCraft parts rebuilding the same things every frame: - The toolbar measures and shows its rail every frame, and each call rebuilt the slots: the stored layout's names parsed back to tools and every rail tool made anew (about a sixth of the UI pass). The slots depend on the layout alone, so `tool_commands::slots` keeps the last layout and its slots and builds again only for a different layout. - The menu bar's command gate asks `bridge_of` for each item every frame, and it built every row's `CommandRef` (an allocated id) to compare (about a tenth of the UI pass). The rows' commands are now built once. Measured on Windows 11 (fresh settings, empty 1600 x 1000 document, two runs each): UI pass during a menu hover 10.1-13.8 ms -> 7.1-8.7 ms, canvas pointer moves 8.7-16.9 ms -> 6.1-7.1 ms. --- crates/ui-egui/src/input/shortcut_dispatch.rs | 10 +++- .../src/input/shortcut_dispatch/tests.rs | 15 ++++++ crates/ui-egui/src/panels/tool_commands.rs | 51 ++++++++++++++++++- crates/ui-egui/src/panels/toolbar.rs | 2 +- 4 files changed, 75 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/input/shortcut_dispatch.rs b/crates/ui-egui/src/input/shortcut_dispatch.rs index 2ed03ef4b4..51db907d55 100644 --- a/crates/ui-egui/src/input/shortcut_dispatch.rs +++ b/crates/ui-egui/src/input/shortcut_dispatch.rs @@ -146,9 +146,17 @@ pub(crate) const RUNTIME_COMMANDS: &[(&str, Bridged)] = &[ ("view.screenMode.cycleBack", Bridged::ScreenMode(ScreenModeCommands::CycleBack)), ]; +/// The framework command of every row of [`RUNTIME_COMMANDS`], built once. `Bridged::command` allocates the +/// command's id, and the menu bar asks [`bridge_of`] for each of its items on every frame (the command gate's +/// [`screen_mode_row`]): building every row's command there cost about a tenth of the UI pass (#15493). +fn bridged_commands() -> &'static [(CommandRef, &'static str, Bridged)] { + static TABLE: std::sync::OnceLock> = std::sync::OnceLock::new(); + TABLE.get_or_init(|| RUNTIME_COMMANDS.iter().map(|(id, bridged)| (bridged.command(), *id, *bridged)).collect()) +} + /// The PhotoCraft id and bridge row of a framework command, if a row bridges it. fn bridge_of(command: &CommandRef) -> Option<(&'static str, Bridged)> { - RUNTIME_COMMANDS.iter().find(|(_, bridged)| bridged.command() == *command).map(|(id, bridged)| (*id, *bridged)) + bridged_commands().iter().find(|(bridged, _, _)| bridged == command).map(|(_, id, bridged)| (*id, *bridged)) } /// Whether the runtime defines command `id` (a row of [`RUNTIME_COMMANDS`]). diff --git a/crates/ui-egui/src/input/shortcut_dispatch/tests.rs b/crates/ui-egui/src/input/shortcut_dispatch/tests.rs index 1c510fc399..da565dce17 100644 --- a/crates/ui-egui/src/input/shortcut_dispatch/tests.rs +++ b/crates/ui-egui/src/input/shortcut_dispatch/tests.rs @@ -707,3 +707,18 @@ fn a_second_pass_in_one_frame_runs_no_command_twice() { crate::app::framework::keys_pass(&mut app, &ctx, egui::RawInput::default(), |_| {}); assert_eq!(count(&app), n + 1, "one press, one duplicate"); } + +/// `bridge_of` answers from the table built once (#15493) exactly as a scan that builds every row's command does: +/// for every row's framework command, and none for a command no row bridges. +#[test] +fn bridge_of_finds_the_row_a_fresh_scan_finds() { + use super::{CommandRef, RUNTIME_COMMANDS, bridge_of}; + let scan = |command: &CommandRef| RUNTIME_COMMANDS.iter().find(|(_, bridged)| bridged.command() == *command).map(|(id, bridged)| (*id, *bridged)); + for (_, bridged) in RUNTIME_COMMANDS { + let command = bridged.command(); + assert_eq!(bridge_of(&command), scan(&command), "{command:?}"); + assert!(bridge_of(&command).is_some(), "{command:?} is bridged"); + } + let unknown = CommandRef::new("photocraft.noSuchCommand"); + assert_eq!(bridge_of(&unknown), None); +} diff --git a/crates/ui-egui/src/panels/tool_commands.rs b/crates/ui-egui/src/panels/tool_commands.rs index 68e63869f2..889f6cf5d9 100644 --- a/crates/ui-egui/src/panels/tool_commands.rs +++ b/crates/ui-egui/src/panels/tool_commands.rs @@ -4,6 +4,8 @@ use craft::ui::contract::CommandSet; use craft::ui::rails::{RailTool, SlotId, ToolSlot}; use photocraft_engine::prefs::ToolbarCustomization; +use std::cell::RefCell; +use std::rc::Rc; use super::toolbar::layout_sections; use crate::state::Tool; @@ -323,9 +325,33 @@ pub(crate) fn rail_tool(tool: Tool) -> RailTool { RailTool::new(tool, command_of(tool)) } +/// A layout and the slots it built. +type KeptSlots = (ToolbarCustomization, Rc>>); + +/// The rail's slots for `toolbar`, built once per layout. The toolbar measures and shows its rail on every frame, and +/// building the slots (the stored layout's names parsed back to tools, every rail tool made anew) cost about a sixth +/// of the UI pass (#15493). The slots depend on the layout alone ([`rail_tool`] on the tool alone), so the last layout +/// and its slots are kept and a different layout builds them again. +pub(crate) fn slots(toolbar: &ToolbarCustomization) -> Rc>> { + thread_local! { + static LAST: RefCell> = const { RefCell::new(None) }; + } + LAST.with(|last| { + let mut last = last.borrow_mut(); + if let Some((layout, slots)) = last.as_ref() + && layout == toolbar + { + return Rc::clone(slots); + } + let slots = Rc::new(build_slots(toolbar)); + *last = Some((toolbar.clone(), Rc::clone(&slots))); + slots + }) +} + /// The rail's slots: one per toolbar group of the stored layout ([`layout_sections`]), the last of each section ending a /// group. A slot's id is its first tool's default slot index, so a slot keeps its id when others move. -pub(crate) fn slots(toolbar: &ToolbarCustomization) -> Vec> { +fn build_slots(toolbar: &ToolbarCustomization) -> Vec> { let mut slots = Vec::new(); for section in layout_sections(toolbar) { let last = section.len().saturating_sub(1); @@ -353,4 +379,27 @@ mod tests { assert_eq!(tool_of(command_of(tool)), tool); } } + + /// The slots as the rail reads them: each slot's id, whether it ends a group, and its tools. + fn shape(slots: &[ToolSlot]) -> String { + format!("{slots:?}") + } + + /// `slots` keeps the last layout's slots: the same layout is served from the cache, and a different layout (or + /// back to the first) gets the slots that layout builds, never the kept ones. + #[test] + fn slots_are_built_once_per_layout_and_follow_a_layout_change() { + let default = ToolbarCustomization::default(); + let first = slots(&default); + assert_eq!(shape(&first), shape(&build_slots(&default)), "the cached slots are the built ones"); + assert!(Rc::ptr_eq(&first, &slots(&default)), "the same layout is served from the cache"); + + let mut changed = ToolbarCustomization::default(); + changed.hidden = vec!["Brush".to_string()]; + let after = slots(&changed); + assert_eq!(shape(&after), shape(&build_slots(&changed)), "a changed layout builds its own slots"); + assert_ne!(shape(&after), shape(&first), "hiding a tool changes the slots"); + + assert_eq!(shape(&slots(&default)), shape(&build_slots(&default)), "back to the first layout, its slots again"); + } } diff --git a/crates/ui-egui/src/panels/toolbar.rs b/crates/ui-egui/src/panels/toolbar.rs index acb14c1d00..6f9fa4de66 100644 --- a/crates/ui-egui/src/panels/toolbar.rs +++ b/crates/ui-egui/src/panels/toolbar.rs @@ -217,7 +217,7 @@ pub fn toolbar(app: &mut PhotocraftApp, ui: &mut egui::Ui) { _ => {} } if let Some(next) = &out.last_used { - for slot in &slots { + for slot in slots.iter() { if let Some(tool) = next.get(slot.id) && remembered.get(slot.id) != Some(tool) { From 7dc7037f6a9bc7ea58df56f44c1c68432e3991d9 Mon Sep 17 00:00:00 2001 From: David Mann Date: Tue, 17 Nov 2026 21:41:06 +0100 Subject: [PATCH 02/10] perf(ui): keep the toolbar rail's measured height until what it depends on changes (#15493) The dock asks the toolbar's group for its height on every frame before it shows the rail, and that measuring run (every tool button and the footer, each resolving its command) was the largest part of the UI pass after the first fixes: about three quarters of all measuring. `toolbar::measure` keeps the last height with what it depends on (width, room, slots, flyout side, Edit Toolbar drawer, scale, direction and the resolved tokens, which change with the theme, the UI font size and the UI scale) and measures again only when one of them changes. Checked in the app: after changing the UI font size, the UI scale and the theme while it runs, the toolbar matches a fresh start with the same settings. Measured (Windows 11, idle machine, three runs, with the earlier fixes and storytold/craft-libs#2082): UI pass with the pointer over the canvas 4.9-5.0 ms -> 3.7-4.3 ms, during a menu hover 6.7-7.1 ms -> 4.1-5.0 ms. Also writes the slots test's customization in one initializer (clippy). --- crates/ui-egui/src/panels/tool_commands.rs | 3 +- crates/ui-egui/src/panels/toolbar.rs | 60 +++++++++++++++++ .../src/panels/toolbar_measure_tests.rs | 65 +++++++++++++++++++ 3 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 crates/ui-egui/src/panels/toolbar_measure_tests.rs diff --git a/crates/ui-egui/src/panels/tool_commands.rs b/crates/ui-egui/src/panels/tool_commands.rs index 889f6cf5d9..a1b328d1d0 100644 --- a/crates/ui-egui/src/panels/tool_commands.rs +++ b/crates/ui-egui/src/panels/tool_commands.rs @@ -394,8 +394,7 @@ mod tests { assert_eq!(shape(&first), shape(&build_slots(&default)), "the cached slots are the built ones"); assert!(Rc::ptr_eq(&first, &slots(&default)), "the same layout is served from the cache"); - let mut changed = ToolbarCustomization::default(); - changed.hidden = vec!["Brush".to_string()]; + let changed = ToolbarCustomization { hidden: vec!["Brush".to_string()], ..ToolbarCustomization::default() }; let after = slots(&changed); assert_eq!(shape(&after), shape(&build_slots(&changed)), "a changed layout builds its own slots"); assert_ne!(shape(&after), shape(&first), "hiding a tool changes the slots"); diff --git a/crates/ui-egui/src/panels/toolbar.rs b/crates/ui-egui/src/panels/toolbar.rs index 6f9fa4de66..4c5e818c81 100644 --- a/crates/ui-egui/src/panels/toolbar.rs +++ b/crates/ui-egui/src/panels/toolbar.rs @@ -18,6 +18,10 @@ use super::tool_commands; #[path = "toolbar_tab_reveal_tests.rs"] mod toolbar_tab_reveal_tests; +#[cfg(test)] +#[path = "toolbar_measure_tests.rs"] +mod toolbar_measure_tests; + // ----------------------------------------------------------------------------- toolbar /// Tool groups separated by hairlines, Photoshop order. @@ -179,8 +183,64 @@ fn footer(app: &mut PhotocraftApp, ui: &mut egui::Ui, rail: RailFooter) { }); } +/// What the rail's measured height depends on: the width and room it is laid out in, the slots (the same `Rc` while +/// the layout is the same), where its flyouts open, the Edit Toolbar drawer, and the scale, direction and resolved +/// tokens (theme, density, text size) it is drawn with. The current and remembered tools change which icon a button +/// shows, not its size, and the footer's buttons keep their sizes whatever they show. +#[derive(Clone)] +struct MeasureKey { + width: u32, + room: [u32; 2], + slots: std::rc::Rc>>, + opens: Side, + editing: bool, + pixels_per_point: u32, + rtl: bool, + tokens: std::sync::Arc, +} + +impl PartialEq for MeasureKey { + fn eq(&self, other: &Self) -> bool { + (self.width, self.room, self.opens, self.editing, self.pixels_per_point, self.rtl) + == (other.width, other.room, other.opens, other.editing, other.pixels_per_point, other.rtl) + && std::rc::Rc::ptr_eq(&self.slots, &other.slots) + && std::sync::Arc::ptr_eq(&self.tokens, &other.tokens) + } +} + /// The height of the toolbar's rail laid out `width` wide: as many tool columns as `width` holds, with the footer. +/// +/// The dock asks for it on every frame before it shows the rail, and a measuring run of the rail (every tool button +/// and the footer, each resolving its command) was the largest part of the UI pass (#15493). The last height is kept +/// with what it depends on ([`MeasureKey`]) and measured again only when one of them changes. pub(crate) fn measure(app: &mut PhotocraftApp, ui: &egui::Ui, width: f32) -> f32 { + thread_local! { + static LAST: std::cell::RefCell> = const { std::cell::RefCell::new(None) }; + } + let slots = tool_commands::slots(&app.session.prefs().toolbar); + let (opens, editing) = (crate::panel_docking::toolbar_opens(app), app.ui.toolbar_drawer); + let env = craft::ui::runtime::env::Env::of(ui); + let room = ui.available_size(); + let key = MeasureKey { + width: width.to_bits(), + room: [room.x.to_bits(), room.y.to_bits()], + slots: std::rc::Rc::clone(&slots), + opens, + editing, + pixels_per_point: ui.ctx().pixels_per_point().to_bits(), + rtl: env.direction.is_rtl(), + tokens: std::sync::Arc::clone(&env.tokens), + }; + if let Some(height) = LAST.with(|last| last.borrow().as_ref().filter(|(kept, _)| *kept == key).map(|(_, height)| *height)) { + return height; + } + let height = measure_now(app, ui, width); + LAST.with(|last| *last.borrow_mut() = Some((key, height))); + height +} + +/// [`measure`] without the kept height: a measuring run of the rail. +fn measure_now(app: &mut PhotocraftApp, ui: &egui::Ui, width: f32) -> f32 { let slots = tool_commands::slots(&app.session.prefs().toolbar); let remembered = last_used(&slots, &app.ui.group_tools); let current = app.ui.tool; diff --git a/crates/ui-egui/src/panels/toolbar_measure_tests.rs b/crates/ui-egui/src/panels/toolbar_measure_tests.rs new file mode 100644 index 0000000000..919c67ffee --- /dev/null +++ b/crates/ui-egui/src/panels/toolbar_measure_tests.rs @@ -0,0 +1,65 @@ +//! The kept height of the toolbar's rail (#15493): `measure` answers as a measuring run does, and measures again +//! when the width or the toolbar layout changes. + +use super::*; +use crate::app::framework::BuildApp; +use std::cell::{Cell, RefCell}; +use std::rc::Rc; + +/// What one pass measured: the width, the kept height and a fresh measuring run's. +type Seen = Rc>>; + +/// A harness that measures the rail `width` wide on every pass, through `measure` and through a fresh run. +fn harness(width: Rc>, seen: Seen) -> egui_kittest::Harness<'static, PhotocraftApp> { + let mut ready = false; + let app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default()); + let mut harness = egui_kittest::Harness::builder().with_context(app.ctx().clone()).with_size(vec2(400.0, 900.0)).build_app( + move |ui, app: &mut PhotocraftApp| { + if !ready { + egui_extras::install_image_loaders(ui.ctx()); + crate::theme::install_fonts(ui.ctx()); + crate::theme::apply(ui.ctx(), &crate::theme::AppTheme::pro()); + ready = true; + return; + } + let w = width.get(); + let kept = measure(app, ui, w); + let fresh = measure_now(app, ui, w); + seen.borrow_mut().push((w, kept, fresh)); + }, + app, + ); + harness.run_steps(4); + harness +} + +fn last(seen: &Seen) -> (f32, f32, f32) { + *seen.borrow().last().expect("a pass measured the rail") +} + +#[test] +fn the_kept_height_follows_the_width_and_the_toolbar_layout() { + let width = Rc::new(Cell::new(40.0)); + let seen: Seen = Rc::default(); + let mut harness = harness(Rc::clone(&width), Rc::clone(&seen)); + + let (_, one_column, fresh) = last(&seen); + assert_eq!(one_column, fresh, "one column: the kept height is the measured one"); + harness.run_steps(2); + assert_eq!(last(&seen).1, one_column, "the same inputs keep the height"); + + width.set(120.0); + harness.run_steps(2); + let (_, wide, fresh) = last(&seen); + assert_eq!(wide, fresh, "a wider rail is measured again"); + assert!(wide < one_column, "more columns make a shorter rail: {wide} against {one_column}"); + + // Hide most tools: the layout changes, and with it the slots. + harness.state_mut().session.prefs.edit(|prefs| { + prefs.toolbar.hidden = Tool::ALL.iter().skip(4).map(|tool| format!("{tool:?}")).collect(); + }); + harness.run_steps(2); + let (_, fewer, fresh) = last(&seen); + assert_eq!(fewer, fresh, "a changed layout is measured again"); + assert!(fewer < wide, "fewer tools make a shorter rail: {fewer} against {wide}"); +} From 93dc0493bfc29c4cd1ddf3390dfb000a19ed6360 Mon Sep 17 00:00:00 2001 From: David Mann Date: Tue, 17 Nov 2026 22:00:58 +0100 Subject: [PATCH 03/10] perf(ui): the toolbar rail settles like a panel body (#15493) The dock replays a panel body's last run while its content version is unchanged and no input reaches it, but the toolbar's group view ran every tool button through the full component pipeline on every frame: the largest part of the UI pass after the earlier fixes. The rail now shows in a settling `Lazy` with `region_versions::toolbar`: what every region holds (tool, colours, commands run, document) plus the tools the slots remember, the stored layout, the Edit Toolbar drawer, the flyout side, the screen mode and the resolved tokens (theme, UI font size, UI scale). Input over the rail, a change of its room or scale, or a repaint it asks for runs it as before. Checked in the app: a tool picked by key and by click, swapped colours, a group's other tool (Shift+M) and a live theme change all show at once; the toolbar, docking and Tab-reveal tests pass. Measured (Windows 11, idle machine, three runs, with the earlier fixes and storytold/craft-libs#2082): UI pass with the pointer over the canvas 3.7-4.3 ms -> 2.0 ms (about 237 fps, the app's cap), during a menu hover 4.1-5.0 ms -> 2.5-2.7 ms; pointer feedback 12-13 ms. --- crates/ui-egui/src/panels/panel_docking.rs | 8 +++- crates/ui-egui/src/panels/region_versions.rs | 45 ++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/panels/panel_docking.rs b/crates/ui-egui/src/panels/panel_docking.rs index 596f12af47..1d5536e022 100644 --- a/crates/ui-egui/src/panels/panel_docking.rs +++ b/crates/ui-egui/src/panels/panel_docking.rs @@ -8,7 +8,7 @@ use craft::behavior::dock::{Action, DockEdge, DockPlacement, Layout, Node, PanelPlace, PanelState, Permissions, SplitSize, Target}; use craft::behavior::overlay::Side; use craft::behavior::{DockSide, EditEvent, EditEvents, IconId}; -use craft::ui::contract::{Bind, BodyCx, SizeLimits}; +use craft::ui::contract::{Bind, BodyCx, Lazy, SizeLimits}; use craft::ui::docking::{ DockCommands, DockConfig, DockEvent, DockPanels, DockScene, DockSizes, DockTo, DragUnit, FloatSpace, GroupAt, HidePanels, PanelSpec, actions, move_actions, request_actions, @@ -197,7 +197,11 @@ impl DockPanels for Panels<'_> { return Some(match at { GroupAt::Measure(width) => super::toolbar::measure(self.app, ui, width), GroupAt::Show(rect) => { - super::toolbar::toolbar(self.app, ui); + // The rail settles as a panel body does: while nothing it shows changed and no input reaches it, + // the frame repaints its last run instead of running every tool button again (#15493). + let version = super::region_versions::toolbar(self.app, ui); + let app = &mut *self.app; + Lazy::new("toolbar", 0.0).settles(true).content(version).show(ui, |ui| super::toolbar::toolbar(app, ui)); rect.height() } }); diff --git a/crates/ui-egui/src/panels/region_versions.rs b/crates/ui-egui/src/panels/region_versions.rs index 889f825822..db0373493b 100644 --- a/crates/ui-egui/src/panels/region_versions.rs +++ b/crates/ui-egui/src/panels/region_versions.rs @@ -38,6 +38,24 @@ pub(crate) fn panel(app: &PhotocraftApp, id: &str) -> u64 { } } +/// The version of the toolbar's rail (#15493): what every region holds (the tool, the colours of its chips, the +/// commands run), the tools each slot remembers, the stored toolbar layout, the Edit Toolbar drawer, the side its +/// flyouts open on, the screen mode its footer button shows, and the resolved tokens it was drawn with (they change +/// with the theme, the UI font size and the UI scale), so a theme change redraws it even without a command. +pub(crate) fn toolbar(app: &PhotocraftApp, ui: &egui::Ui) -> u64 { + toolbar_with(app, std::sync::Arc::as_ptr(&craft::ui::runtime::env::Env::of(ui).tokens) as usize) +} + +/// [`toolbar`] with the tokens it was drawn with named by `tokens`. +fn toolbar_with(app: &PhotocraftApp, tokens: usize) -> u64 { + let layout = &app.session.prefs().toolbar; + let mode = format!("{:?}", app.ui.view.screen_mode); + version( + app, + (&app.ui.group_tools, (&layout.hidden, &layout.toolbar, &layout.extras), app.ui.toolbar_drawer, crate::panel_docking::toolbar_opens(app), mode, tokens), + ) +} + /// What every region may show, joined with `extra`: the commands run (any of them may change anything), the active /// document, its revision and its active layers, the tool, the colours and the brush. fn version(app: &PhotocraftApp, extra: impl Hash) -> u64 { @@ -61,3 +79,30 @@ fn view(app: &PhotocraftApp) -> Option<[u64; 5]> { crate::canvas::active_view(app) .map(|view| [view.zoom.to_bits(), view.center.x.to_bits(), view.center.y.to_bits(), view.rotation.to_bits(), u64::from(view.flip_x)]) } + +#[cfg(test)] +mod tests { + use super::*; + use crate::state::Tool; + + /// Everything the settled toolbar shows moves its version (#15493): a version that missed one would replay a stale + /// rail. The same state gives the same version, so the rail settles. + #[test] + fn the_toolbar_version_moves_with_what_the_rail_shows() { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default()); + let base = toolbar_with(&app, 1); + assert_eq!(toolbar_with(&app, 1), base, "the same state settles"); + assert_ne!(toolbar_with(&app, 2), base, "other tokens (theme, UI font size or scale)"); + + let changed = |name: &str, change: &dyn Fn(&mut PhotocraftApp), app: &mut PhotocraftApp| { + let before = toolbar_with(app, 1); + change(app); + assert_ne!(toolbar_with(app, 1), before, "{name} moves the version"); + }; + changed("the tool", &|app| app.ui.tool = Tool::Brush, &mut app); + changed("a slot's remembered tool", &|app| app.ui.group_tools.insert(0, Tool::EllipseMarquee), &mut app); + changed("the Edit Toolbar drawer", &|app| app.ui.toolbar_drawer = !app.ui.toolbar_drawer, &mut app); + changed("the toolbar layout", &|app| app.session.prefs.edit(|prefs| prefs.toolbar.hidden.push("Brush".to_string())), &mut app); + changed("the colours", &|app| app.session.tools.foreground[0] = 0.25, &mut app); + } +} From e7a5c9e316dd43943a5e76fd003c8f7060ba4526 Mon Sep 17 00:00:00 2001 From: NaufalDzz Date: Tue, 17 Nov 2026 21:06:01 +0000 Subject: [PATCH 04/10] =?UTF-8?q?Menus:=20Window=20=E2=80=BA=20Contextual?= =?UTF-8?q?=20Task=20Bar=20tick=20follows=20the=20bar=20(#15489)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The menus are rebuilt only when `state_hash` changes or input arrives, and the hash left out the Window bars' flags. Hiding the contextual task bar with its Hide bar or `ui.set` therefore kept a stale tick. Hash the bars' on/off flags (not the task bar's place, which moves during a drag). Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com> --- crates/ui-egui/src/menus/native_menu.rs | 4 ++++ crates/ui-egui/src/menus/native_menu/tests.rs | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/crates/ui-egui/src/menus/native_menu.rs b/crates/ui-egui/src/menus/native_menu.rs index f728cd13b9..793776e391 100644 --- a/crates/ui-egui/src/menus/native_menu.rs +++ b/crates/ui-egui/src/menus/native_menu.rs @@ -98,6 +98,10 @@ pub(crate) fn state_hash(app: &PhotocraftApp, input: Option) -> u64 { (&ui.recent_files, &app.workspaces.set.current, app.ui.palette.open, ui.transform.is_some(), ui.text_edit.is_some(), app.dialog_count()).hash(&mut h); // Cut and Copy are enabled while the typed text has a selection. ui.text_edit.as_ref().map(|e| e.anchor != e.caret).hash(&mut h); + // The Window bars' ticks; the Contextual Task Bar's Hide bar and `ui.set` change them without a menu click (#15489). + // Not the task bar's place, which moves every frame of a drag. + let p = &ui.panels; + (p.options_bar, p.status_bar, p.menu_bar, p.context_task_bar).hash(&mut h); (app.discard.is_some(), crate::distort_ui::modal_workspace(app)).hash(&mut h); crate::prefs_ui::recording(app).hash(&mut h); // The rows show the keymap's chords; the keymap follows these from the frame they change. diff --git a/crates/ui-egui/src/menus/native_menu/tests.rs b/crates/ui-egui/src/menus/native_menu/tests.rs index fbe2d2b5fe..870ea9661f 100644 --- a/crates/ui-egui/src/menus/native_menu/tests.rs +++ b/crates/ui-egui/src/menus/native_menu/tests.rs @@ -219,3 +219,21 @@ fn opening_or_closing_a_workspace_without_input_rebuilds_the_menus() { app.framework.dialogs.cancel_by_id(&ctx, id); assert_eq!(state_hash(&app, None), closed, "and come back when it is cancelled"); } + +/// The Contextual Task Bar's tick follows the bar when its Hide bar or `ui.set` turns it off without a menu click +/// (#15489). +#[test] +fn the_task_bar_tick_follows_the_bar_hidden_without_a_menu_click() { + let (mut h, synced, _) = harness(true); + let ticked = |synced: &Synced| { + let bar = synced.borrow().last().cloned().expect("menus synced"); + bar.find(&CommandRef::new("window.panel.contextualTaskBar")).and_then(|it| it.kind.checked()) + }; + assert_eq!(ticked(&synced), Some(true)); + h.state_mut().ui.panels.context_task_bar = false; + h.run_steps(2); + assert_eq!(ticked(&synced), Some(false), "unticked once the bar is hidden"); + h.state_mut().ui.panels.context_task_bar = true; + h.run_steps(2); + assert_eq!(ticked(&synced), Some(true), "ticked again once it shows"); +} From beb55416ab05ba30bac89aba1b1596360c59079a Mon Sep 17 00:00:00 2001 From: ljkx <177671075+ljkx@users.noreply.github.com> Date: Wed, 18 Nov 2026 01:28:43 +0100 Subject: [PATCH 05/10] Pen: Delete on a kept draft takes back one anchor, not the whole draft (#15488) A Pen draft whose commit was refused is kept with `commit_failed`, which tells `cancel_stale_pen` to leave it for an explicit retry once its document has changed. `set_draft` cleared that flag on every edit the Pen reported, including the one Delete and Backspace send. After the document changed under the kept draft (Delete under another tool deletes the active layer), the first Delete back under the Pen cleared the flag and the next pass dropped the whole draft as stale. Keep the flag when the draft's owner is stale. Such a draft takes no press (`configure` turns sensing off), so only Delete and Backspace edit it, as before the craft UI port, where only a press cleared the flag. Every other edit still clears it. Adds a_kept_pen_draft_takes_delete_only_under_its_own_tool for the Pen and the Curvature Pen. --- crates/ui-egui/src/tools/vector_ui/host.rs | 5 ++- .../src/tools/vector_ui/pen_resume_tests.rs | 33 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/tools/vector_ui/host.rs b/crates/ui-egui/src/tools/vector_ui/host.rs index c91fa8b7c3..066bae8a85 100644 --- a/crates/ui-egui/src/tools/vector_ui/host.rs +++ b/crates/ui-egui/src/tools/vector_ui/host.rs @@ -308,6 +308,9 @@ fn edit_draft(app: &mut PhotocraftApp, edit: EditEvent) -> bool { fn set_draft(app: &mut PhotocraftApp, value: EditSubpath) { let n = value.knots.len(); let selection_on_draft = app.ui.direct_selection.target == Some(PathRef::Pen); + // A refused draft whose document changed since takes no press, only Delete and Backspace: it stays refused, or + // `cancel_stale_pen` would drop all of it on the next pass instead of the one anchor (#15488). + let stale = app.ui.pen.as_ref().and_then(|p| p.owner.as_ref()).is_some_and(|o| !o.valid(app)); let Some(pen) = ensure_draft(app) else { return }; if pen.draft == value { return; @@ -325,7 +328,7 @@ fn set_draft(app: &mut PhotocraftApp, value: EditSubpath) { } } pen.draft = value; - pen.commit_failed = false; + pen.commit_failed &= stale; if selection_on_draft { let ds = &mut app.ui.direct_selection; if grew { diff --git a/crates/ui-egui/src/tools/vector_ui/pen_resume_tests.rs b/crates/ui-egui/src/tools/vector_ui/pen_resume_tests.rs index 0244f56d10..796b6587c8 100644 --- a/crates/ui-egui/src/tools/vector_ui/pen_resume_tests.rs +++ b/crates/ui-egui/src/tools/vector_ui/pen_resume_tests.rs @@ -735,3 +735,36 @@ fn freeform_selection_does_not_claim_a_failed_pen_or_curvature_draft() { } } } + +/// A refused Pen draft is kept (#15488): under another tool, Delete is that tool's (the active layer goes); back under +/// the Pen that drew it, Delete takes back one anchor at a time, as while drawing, and only the last anchor drops the +/// draft. +#[test] +fn a_kept_pen_draft_takes_delete_only_under_its_own_tool() { + for tool in [Tool::Pen, Tool::CurvaturePen] { + let mut app = app(); + app.run("layer.new.layer", json!({})).unwrap(); + app.ui.tool = tool; + app.ui.tool_options.vector_mode = craft::draw::ui::shape::VectorMode::Path; + three_anchors(&mut app); + app.session.authorize = Some(|id, _| if id == "path.set" { Err(photocraft_engine::EngineError::Other("refused path fixture".into())) } else { Ok(()) }); + assert!(!pen_commit(&mut app, false), "the fixture must actually refuse the commit"); + app.session.authorize = None; + assert_eq!(app.ui.pen.as_ref().unwrap().draft.knots.len(), 3); + let layers = app.session.active().unwrap().doc.layers.len(); + + switch_tool(&mut app, Tool::AddAnchorPoint); + press(&mut app, egui::Key::Delete, egui::Modifiers::NONE); + assert_eq!(app.session.active().unwrap().doc.layers.len(), layers - 1, "{tool:?}: Delete is the other tool's: the layer goes"); + assert_eq!(app.ui.pen.as_ref().map(|p| p.draft.knots.len()), Some(3), "{tool:?}: the kept draft is untouched"); + + switch_tool(&mut app, tool); + for left in [2, 1] { + press(&mut app, egui::Key::Delete, egui::Modifiers::NONE); + assert_eq!(app.ui.pen.as_ref().map(|p| p.draft.knots.len()), Some(left), "{tool:?}: Delete takes back one anchor ({})", app.ui.status); + } + assert_eq!(app.session.active().unwrap().doc.layers.len(), layers - 1, "{tool:?}: no other layer went"); + press(&mut app, egui::Key::Delete, egui::Modifiers::NONE); + assert!(app.ui.pen.is_none(), "{tool:?}: the last anchor drops the draft"); + } +} From a186cd3557bd1aa90db741aed8fd24563e20ca2a Mon Sep 17 00:00:00 2001 From: NaufalDzz Date: Wed, 18 Nov 2026 05:52:19 +0000 Subject: [PATCH 06/10] Options bar: redraw it when Free Transform ends (#15547) The options bar only reruns when its content version changes. Escape ends Free Transform without a command or a document change, so the version stayed the same and the bar kept the transform fields. The version now covers whether a transform is open. Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com> --- crates/ui-egui/src/panels/region_versions.rs | 5 +++-- .../ui-egui/src/tools/transform_tool/tests.rs | 21 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/panels/region_versions.rs b/crates/ui-egui/src/panels/region_versions.rs index 889f825822..0e4644f6a0 100644 --- a/crates/ui-egui/src/panels/region_versions.rs +++ b/crates/ui-egui/src/panels/region_versions.rs @@ -9,9 +9,10 @@ use std::hash::{Hash, Hasher}; use super::{PhotocraftApp, chrome_ui}; use crate::color_picker_ui::PickWindow; -/// The version of the options bar: the Zoom tool's members show the active view. +/// The version of the options bar: the Zoom tool's members show the active view, and an open Free Transform shows +/// its own members in place of the tool's (Escape ends it without a command, #15547). pub(crate) fn options_bar(app: &PhotocraftApp) -> u64 { - version(app, view(app)) + version(app, (view(app), app.ui.transform.is_some())) } /// The version of the status bar: the zoom readout of the active view, the status message and the item it shows, the diff --git a/crates/ui-egui/src/tools/transform_tool/tests.rs b/crates/ui-egui/src/tools/transform_tool/tests.rs index 0f991ee0fb..6905a3bbeb 100644 --- a/crates/ui-egui/src/tools/transform_tool/tests.rs +++ b/crates/ui-egui/src/tools/transform_tool/tests.rs @@ -2181,3 +2181,24 @@ fn a_waiting_new_layer_click_keeps_the_layer_it_was_made_on() { assert_eq!(at(new), at(placed) + 1, "the new layer sits right above the layer selected at the click: {order:?}"); assert_eq!(st.active_layer, Some(new)); } + +/// #15547: once Escape or Enter ends Free Transform, the options bar shows the active tool's members again in the +/// next frame, not the transform fields. +#[test] +fn ending_the_transform_brings_back_the_tools_options_bar() { + use egui_kittest::kittest::Queryable as _; + for key in [egui::Key::Escape, egui::Key::Enter] { + let mut app = app_with_square(64, photocraft_geom::Rect::new(8, 8, 24, 24)); + app.ui.tool = Tool::Gradient; + let mut h = harness(app, egui::vec2(1400.0, 900.0)); + h.run_steps(4); + let ctx = h.ctx.clone(); + crate::menus::invoke(h.state_mut(), &ctx, "edit.freeTransform", json!({})).unwrap(); + h.run_steps(2); + assert!(h.query_by_label("Reverse").is_none(), "the transform fields replace the Gradient members"); + h.key_press(key); + h.run_steps(2); + assert!(h.state().ui.transform.is_none(), "{key:?} ended the transform"); + assert!(h.query_by_label("Reverse").is_some(), "after {key:?} the Gradient members are back"); + } +} From 5ebc3b4cc9f93a974faa999069df1f5185cd7dc3 Mon Sep 17 00:00:00 2001 From: Zaxaerith <189452125+Zaxaerith@users.noreply.github.com> Date: Wed, 18 Nov 2026 20:22:34 +0800 Subject: [PATCH 07/10] fix(format): drop unused photocraft-formats dependency (#15468) --- Cargo.lock | 1 - crates/format/Cargo.toml | 1 - 2 files changed, 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 31c6c3ba2e..15941dc7c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6456,7 +6456,6 @@ name = "photocraft-format" version = "0.23.1" dependencies = [ "blake3", - "craft-file-formats", "craft-image-codecs", "craft-pcraft-bundle", "craft-pcraft-format", diff --git a/crates/format/Cargo.toml b/crates/format/Cargo.toml index 55dadd78dc..d22c667045 100644 --- a/crates/format/Cargo.toml +++ b/crates/format/Cargo.toml @@ -15,7 +15,6 @@ photocraft-color = { workspace = true } photocraft-raster = { workspace = true } photocraft-doc = { workspace = true } photocraft-codecs = { workspace = true } -photocraft-formats = { workspace = true } craft-pcraft-format = { workspace = true } craft-pcraft-bundle = { workspace = true } craft-zip = { workspace = true } From df7ed10d655525e7dc58257100f172c45ff66009 Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Wed, 18 Nov 2026 16:15:20 +0100 Subject: [PATCH 08/10] test(ui): trace Windows pointer delivery regression Add bounded read-only per-pass snapshots to existing #7366 regression without changing input, frame bound or preservation assertions. Diagnostic only: no root-cause fix claimed. Hosted validation required. --- .../ui-egui/tests/it/remove_channel_target.rs | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/tests/it/remove_channel_target.rs b/crates/ui-egui/tests/it/remove_channel_target.rs index a8ca2950a8..095d15037c 100644 --- a/crates/ui-egui/tests/it/remove_channel_target.rs +++ b/crates/ui-egui/tests/it/remove_channel_target.rs @@ -24,6 +24,27 @@ fn state_line(app: &PhotocraftApp, job: photocraft_engine::jobs::JobId) -> Strin ) } +// Snapshot only existing public read-only inspection fields, before injection and after each +// existing pass. No extra frame or wait is introduced: preserve the pending-job regression. +fn delivery_snapshot(h: &Harness, job: photocraft_engine::jobs::JobId, text: LayerId) -> serde_json::Value { + let state = control::inspect(h.state(), &h.ctx); + let text_bounds = h.state().session.active().and_then(|d| d.doc.layer(text)).and_then(|layer| { + let photocraft_doc::LayerContent::Text(t) = &layer.content else { return None }; + let r = t.cache.as_ref()?.content_bounds(); + Some([r.x0, r.y0, r.x1, r.y1]) + }); + serde_json::json!({ + "state": state_line(h.state(), job), + "textCacheBounds": text_bounds, + "views": state.get("views"), + "rects": state.get("rects"), + "jobs": state.get("jobs"), + "textEdit": state.get("textEdit"), + "tool": state.get("tool"), + "frame": state.get("frame"), + }) +} + fn pixels(s: &Session, doc: usize, id: LayerId) -> Vec { let d = &s.documents()[doc].doc; d.layer(id).unwrap().surface().unwrap().read_region(d.bounds()) @@ -75,6 +96,7 @@ fn probe(input: Input) { }); h.run_steps(4); + let mut delivery_trace = Vec::new(); let job = match h.state_mut().session.start("paint.remove", REMOVE.parse().unwrap()).unwrap() { Started::Job(id) => id, v => panic!("must start a background job: {v:?}"), @@ -82,6 +104,7 @@ fn probe(input: Input) { match input { Input::None => {} Input::ControlPointer => { + delivery_trace.push(delivery_snapshot(&h, job, text)); let ctx = h.ctx.clone(); let (req, _rx) = control::ControlRequest::new("ui.pointer", r#"{"tool":"type","events":[{"kind":"down","x":4,"y":14}]}"#.parse().unwrap()); match control::handle(h.state_mut(), &ctx, &req) { @@ -96,8 +119,9 @@ fn probe(input: Input) { break; } h.run_steps(1); + delivery_trace.push(delivery_snapshot(&h, job, text)); } - let state = state_line(h.state(), job); + let state = format!("{}; delivery trace {delivery_trace:?}", state_line(h.state(), job)); assert!(host.injected_idle(), "the canvas consumed the queued pointer input; {state}"); // `injected_idle` is also true when the step was withdrawn (focus change before its // pass) instead of delivered, so delivery is asserted separately. @@ -105,7 +129,12 @@ fn probe(input: Input) { } } let selected = if matches!(input, Input::None) { target } else { text }; - assert_eq!(h.state().session.active().unwrap().active_layer, Some(selected), "the input selects the text layer; {}", state_line(h.state(), job)); + assert_eq!( + h.state().session.active().unwrap().active_layer, + Some(selected), + "the input selects the text layer; {}; delivery trace {delivery_trace:?}", + state_line(h.state(), job) + ); let a = h.state_mut(); a.session.set_active(1); From 0ed660f313960268b84cccd54a2b44f94bc7d9a0 Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Wed, 18 Nov 2026 18:10:21 +0100 Subject: [PATCH 09/10] test: isolate pending Remove result from progress-modal timing --- .../ui-egui/tests/it/remove_channel_target.rs | 74 ++++++++++--------- 1 file changed, 41 insertions(+), 33 deletions(-) diff --git a/crates/ui-egui/tests/it/remove_channel_target.rs b/crates/ui-egui/tests/it/remove_channel_target.rs index 095d15037c..f8fd9d50a8 100644 --- a/crates/ui-egui/tests/it/remove_channel_target.rs +++ b/crates/ui-egui/tests/it/remove_channel_target.rs @@ -8,7 +8,41 @@ use photocraft_ui_egui::{PhotocraftApp, Services, control}; const REMOVE: &str = r#"{"points":[[12,10],[16,12]],"size":6}"#; -type Harness = egui_kittest::Harness<'static, Box>; +// Drive the real control-input hook and canvas while holding job-result application until +// after selection. The full app's progress modal intentionally blocks canvas input on slow +// hosts, and its logic tick may collect the result before the click, so it is not this +// pending-result regression's fixture. +struct CanvasApp(Box); + +impl std::ops::Deref for CanvasApp { + type Target = PhotocraftApp; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl std::ops::DerefMut for CanvasApp { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} + +impl eframe::App for CanvasApp { + fn raw_input_hook(&mut self, ctx: &egui::Context, input: &mut egui::RawInput) { + eframe::App::raw_input_hook(&mut self.0, ctx, input); + } + + fn logic(&mut self, _ctx: &egui::Context, _frame: &mut eframe::Frame) { + self.sync_views(); + } + + fn ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) { + egui::CentralPanel::default().show(ui, |ui| photocraft_ui_egui::canvas::document_area(&mut self.0, ui)); + } +} + +type Harness = egui_kittest::Harness<'static, CanvasApp>; fn run(s: &mut Session, id: &str, p: &str) { s.execute(id, p.parse().unwrap()).unwrap(); @@ -24,27 +58,6 @@ fn state_line(app: &PhotocraftApp, job: photocraft_engine::jobs::JobId) -> Strin ) } -// Snapshot only existing public read-only inspection fields, before injection and after each -// existing pass. No extra frame or wait is introduced: preserve the pending-job regression. -fn delivery_snapshot(h: &Harness, job: photocraft_engine::jobs::JobId, text: LayerId) -> serde_json::Value { - let state = control::inspect(h.state(), &h.ctx); - let text_bounds = h.state().session.active().and_then(|d| d.doc.layer(text)).and_then(|layer| { - let photocraft_doc::LayerContent::Text(t) = &layer.content else { return None }; - let r = t.cache.as_ref()?.content_bounds(); - Some([r.x0, r.y0, r.x1, r.y1]) - }); - serde_json::json!({ - "state": state_line(h.state(), job), - "textCacheBounds": text_bounds, - "views": state.get("views"), - "rects": state.get("rects"), - "jobs": state.get("jobs"), - "textEdit": state.get("textEdit"), - "tool": state.get("tool"), - "frame": state.get("frame"), - }) -} - fn pixels(s: &Session, doc: usize, id: LayerId) -> Vec { let d = &s.documents()[doc].doc; d.layer(id).unwrap().surface().unwrap().read_region(d.bounds()) @@ -92,19 +105,18 @@ fn probe(input: Input) { let mut h = Harness::builder().with_size(egui::vec2(1100.0, 720.0)).with_max_steps(64).build_eframe(move |cc| { PhotocraftApp::setup_context(&cc.egui_ctx, Default::default()); // The app shares the harness's context, which is where the control channel's pointer input arrives. - PhotocraftApp::with_context(cc.egui_ctx.clone(), a, Services::default()) + CanvasApp(PhotocraftApp::with_context(cc.egui_ctx.clone(), a, Services::default())) }); h.run_steps(4); - let mut delivery_trace = Vec::new(); let job = match h.state_mut().session.start("paint.remove", REMOVE.parse().unwrap()).unwrap() { Started::Job(id) => id, v => panic!("must start a background job: {v:?}"), }; + assert!(h.state().session.job(job).is_some(), "the result is pending before selection"); match input { Input::None => {} Input::ControlPointer => { - delivery_trace.push(delivery_snapshot(&h, job, text)); let ctx = h.ctx.clone(); let (req, _rx) = control::ControlRequest::new("ui.pointer", r#"{"tool":"type","events":[{"kind":"down","x":4,"y":14}]}"#.parse().unwrap()); match control::handle(h.state_mut(), &ctx, &req) { @@ -119,9 +131,8 @@ fn probe(input: Input) { break; } h.run_steps(1); - delivery_trace.push(delivery_snapshot(&h, job, text)); } - let state = format!("{}; delivery trace {delivery_trace:?}", state_line(h.state(), job)); + let state = state_line(h.state(), job); assert!(host.injected_idle(), "the canvas consumed the queued pointer input; {state}"); // `injected_idle` is also true when the step was withdrawn (focus change before its // pass) instead of delivered, so delivery is asserted separately. @@ -129,13 +140,9 @@ fn probe(input: Input) { } } let selected = if matches!(input, Input::None) { target } else { text }; - assert_eq!( - h.state().session.active().unwrap().active_layer, - Some(selected), - "the input selects the text layer; {}; delivery trace {delivery_trace:?}", - state_line(h.state(), job) - ); + assert_eq!(h.state().session.active().unwrap().active_layer, Some(selected), "the input selects the text layer; {}", state_line(h.state(), job)); + assert!(h.state().session.job(job).is_some(), "selection happened before result application"); let a = h.state_mut(); a.session.set_active(1); a.session.wait_job(job).unwrap(); @@ -158,3 +165,4 @@ fn no_input_keeps_red_restriction() { fn control_pointer_click_keeps_red_restriction() { probe(Input::ControlPointer); } + From 3fbff619e4360df204c865317bb0c08f1290af63 Mon Sep 17 00:00:00 2001 From: David Mann Date: Wed, 18 Nov 2026 23:42:00 +0100 Subject: [PATCH 10/10] Pen: the kept-draft Delete test compares the whole draft and checks the layers after the last Delete Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/tools/vector_ui/pen_resume_tests.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/tools/vector_ui/pen_resume_tests.rs b/crates/ui-egui/src/tools/vector_ui/pen_resume_tests.rs index c34302ddeb..0da2cd1948 100644 --- a/crates/ui-egui/src/tools/vector_ui/pen_resume_tests.rs +++ b/crates/ui-egui/src/tools/vector_ui/pen_resume_tests.rs @@ -752,11 +752,12 @@ fn a_kept_pen_draft_takes_delete_only_under_its_own_tool() { app.session.authorize = None; assert_eq!(app.ui.pen.as_ref().unwrap().draft.knots.len(), 3); let layers = app.session.active().unwrap().doc.layers.len(); + let kept = app.ui.pen.as_ref().unwrap().draft.clone(); switch_tool(&mut app, Tool::AddAnchorPoint); press(&mut app, egui::Key::Delete, egui::Modifiers::NONE); assert_eq!(app.session.active().unwrap().doc.layers.len(), layers - 1, "{tool:?}: Delete is the other tool's: the layer goes"); - assert_eq!(app.ui.pen.as_ref().map(|p| p.draft.knots.len()), Some(3), "{tool:?}: the kept draft is untouched"); + assert_eq!(app.ui.pen.as_ref().map(|p| &p.draft), Some(&kept), "{tool:?}: the kept draft is untouched"); switch_tool(&mut app, tool); for left in [2, 1] { @@ -766,5 +767,6 @@ fn a_kept_pen_draft_takes_delete_only_under_its_own_tool() { assert_eq!(app.session.active().unwrap().doc.layers.len(), layers - 1, "{tool:?}: no other layer went"); press(&mut app, egui::Key::Delete, egui::Modifiers::NONE); assert!(app.ui.pen.is_none(), "{tool:?}: the last anchor drops the draft"); + assert_eq!(app.session.active().unwrap().doc.layers.len(), layers - 1, "{tool:?}: the last Delete is the drawing tool's too"); } }