From 4f338e03aecaa93e03f9a596138c54eecc5091b5 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Fri, 27 Nov 2026 17:11:05 +0000 Subject: [PATCH] Connector rerouting no longer unshares the edited slide, the shape group is named Decorative Text Styles, and a socket request is tested as answered in the frame reroute read the glued connectors through the mutable shape list, so every edit copied the selected slide and its thumbnail was drawn again. The shape-format group said WordArt, which production never displayed. A control request over the real server is answered by the UI frame. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/connect.rs | 5 ++-- crates/engine/src/lib.rs | 19 ++++++++------ crates/ui-egui/src/control.rs | 32 +++++++++++++++++++++++ crates/ui-egui/src/ribbon/shape_format.rs | 2 +- 4 files changed, 47 insertions(+), 11 deletions(-) diff --git a/crates/engine/src/connect.rs b/crates/engine/src/connect.rs index 5991ba619..3a2c491f4 100644 --- a/crates/engine/src/connect.rs +++ b/crates/engine/src/connect.rs @@ -100,10 +100,11 @@ pub fn endpoints(x: &Xfrm) -> (Point, Point) { /// Move the ends of connectors glued to shapes on the edited slide to the current site positions. /// Connections to shapes that no longer exist are dropped. pub fn reroute(doc: &mut Presentation, sel: &Selection) { - let Some(list) = crate::shapes_mut(doc, sel) else { return }; - if !list.iter().any(|s| matches!(s.kind, ShapeKind::Connector { start: Some(_), .. } | ShapeKind::Connector { end: Some(_), .. })) { + // Read first: taking the list mutably would unshare the edited slide even when no connector is glued. + if !crate::shapes_of(doc, sel).iter().any(|s| matches!(s.kind, ShapeKind::Connector { start: Some(_), .. } | ShapeKind::Connector { end: Some(_), .. })) { return; } + let Some(list) = crate::shapes_mut(doc, sel) else { return }; let snapshot: Vec = list.clone(); let view = doc.clone(); let site = |id: ShapeId, idx: u32| -> Option { diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index bf91dee3e..e377a1b14 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -288,14 +288,7 @@ impl DocState { } /// Shapes of the edited tree (current slide, or the master/layout in Slide Master view). pub fn shapes(&self) -> &[Shape] { - match self.selection.target { - Target::Slides => self.current_slide().map(|s| s.shapes.as_slice()).unwrap_or(&[]), - Target::Master { master } => self.doc.masters.get(master).map(|m| m.shapes.as_slice()).unwrap_or(&[]), - Target::Handout | Target::NotesMaster => page_master(&self.doc, self.selection.target).map(|m| m.shapes.as_slice()).unwrap_or(&[]), - Target::Layout { master, layout } => { - self.doc.masters.get(master).and_then(|m| m.layouts.get(layout)).map(|l| l.shapes.as_slice()).unwrap_or(&[]) - } - } + shapes_of(&self.doc, &self.selection) } pub fn shape(&self, id: ShapeId) -> Option<&Shape> { deckcraft_model::find_shape(self.shapes(), id) @@ -321,6 +314,16 @@ pub fn master_page(doc: &Presentation, t: Target) -> Option { Some(p) } +/// The edited shape tree of a presentation, read without unsharing its slide or master. +pub fn shapes_of<'a>(doc: &'a Presentation, sel: &Selection) -> &'a [Shape] { + match sel.target { + Target::Slides => doc.slides.get(sel.slide).map(|s| s.shapes.as_slice()).unwrap_or(&[]), + Target::Master { master } => doc.masters.get(master).map(|m| m.shapes.as_slice()).unwrap_or(&[]), + Target::Handout | Target::NotesMaster => page_master(doc, sel.target).map(|m| m.shapes.as_slice()).unwrap_or(&[]), + Target::Layout { master, layout } => doc.masters.get(master).and_then(|m| m.layouts.get(layout)).map(|l| l.shapes.as_slice()).unwrap_or(&[]), + } +} + /// Mutable access to the edited shape tree of a presentation. pub fn shapes_mut<'a>(doc: &'a mut Presentation, sel: &Selection) -> Option<&'a mut Vec> { match sel.target { diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rs index d08161dc6..d3f6ab586 100644 --- a/crates/ui-egui/src/control.rs +++ b/crates/ui-egui/src/control.rs @@ -974,4 +974,36 @@ mod tests { assert!(harness.state().show.is_none(), "an invalid start never launches a show"); Ok(()) } + + /// A request from a client's own thread is answered by the UI thread's frame: the connection thread only + /// forwards it and asks for a repaint, so it never touches a running pass's state. + #[cfg(not(target_arch = "wasm32"))] + #[test] + fn a_request_over_the_socket_is_answered_in_the_frame() -> Result<(), Box> { + use craft::automation::{client::ControlClient, server}; + + let mut harness = harness_with( + deckcraft_engine::Session::with_new(), + crate::Services::default(), + egui_kittest::Harness::builder().with_size(egui::vec2(1440.0, 900.0)).with_step_dt(1.0 / 60.0), + |_| {}, + ); + let listener = std::net::TcpListener::bind(("127.0.0.1", 0))?; + let (receiver, listening) = server::serve(listener, "token".into(), WindowHost::of(&harness.ctx))?; + harness.state_mut().control = Some(ControlChannel::new(receiver)); + let addr = listening.addr; + let notice = "A notice sent over the socket"; + let client = std::thread::spawn(move || ControlClient::connect(addr, "token").map_err(|e| format!("{e:?}"))?.call("ui.notify", json!({"text": notice}))); + let mut frames = 0; + while !client.is_finished() && frames < 600 { + harness.run_steps(1); + std::thread::sleep(std::time::Duration::from_millis(5)); + frames += 1; + } + assert!(client.is_finished(), "the frame answered the request"); + client.join().map_err(|_| "the client thread panicked")??; + harness.run_steps(2); + assert!(harness.query_by_label(notice).is_some(), "the request ran in the frame"); + Ok(()) + } } diff --git a/crates/ui-egui/src/ribbon/shape_format.rs b/crates/ui-egui/src/ribbon/shape_format.rs index 69114b1d2..6138501cf 100644 --- a/crates/ui-egui/src/ribbon/shape_format.rs +++ b/crates/ui-egui/src/ribbon/shape_format.rs @@ -170,7 +170,7 @@ pub(crate) fn shape_format(app: &mut SlideApp, row: &mut RibbonRow<'_>) { Menu::new("Shape Effects").opened_by(&response.response, Trigger::Click).show(ui, |ui, cx| effects_menu(app, ui, cx)); }); }); - row.group(RibbonGroup::new("shapeFormat.wordArt", "WordArt Styles", Icon::TextEffects.id().into()), |ui| { + row.group(RibbonGroup::new("shapeFormat.wordArt", "Decorative Text Styles", Icon::TextEffects.id().into()), |ui| { Stack::new().show(ui, |ui, _| { let response = Button::new("Text Fill") .icon(Icon::TextFill.id())