From c3184b74f94cc6299418830c5f4fca67b1eacb75 Mon Sep 17 00:00:00 2001 From: Francisco Herrera <14956584+alosslessdev@users.noreply.github.com> Date: Wed, 21 Oct 2026 15:16:30 -0500 Subject: [PATCH] Address CodeRabbit review: borrow the workbook and keep both swatch outlines (#2148) --- crates/ui-egui/src/ribbon.rs | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/crates/ui-egui/src/ribbon.rs b/crates/ui-egui/src/ribbon.rs index 742ee80cb..a7ca0ad6a 100644 --- a/crates/ui-egui/src/ribbon.rs +++ b/crates/ui-egui/src/ribbon.rs @@ -2334,24 +2334,32 @@ const RIBBON_TABLE_STYLES: [&str; 7] = ["TableStyleLight1", "TableStyleLight2", "TableStyleLight3", "TableStyleLight4", "TableStyleLight5", "TableStyleLight6", "TableStyleLight7"]; fn table_style_strip(app: &mut SheetApp, ui: &mut Ui, tname: &str, current: &str) { - let Some(wb) = app.session.active().map(|d| d.wb.clone()) else { return }; let t = Tokens::get(ui.ctx()); ui.add_space(12.0); ui.horizontal(|ui| { ui.spacing_mut().item_spacing.x = 3.0; - for name in RIBBON_TABLE_STYLES { - let (r, resp) = ui.allocate_exact_size(vec2(52.0, 40.0), Sense::click()); - paint_table_swatch(ui, r, &wb, name); - if resp.hovered() { - ui.painter().rect_stroke(r.expand(1.5), 2.0, Stroke::new(2.0, Color32::from_rgb(0xE8, 0x7D, 0x2B)), StrokeKind::Outside); - } - if name == current { - ui.painter().rect_stroke(r.expand(1.5), 2.0, Stroke::new(2.0, t.accent), StrokeKind::Outside); - } - let resp = resp.on_hover_text(name); - if resp.clicked() { - act(app, "table.style", json!({"table": tname, "style": name})); + // Borrow the workbook only while painting; the session must be free for `act` afterwards. + let clicked = { + let Some(d) = app.session.active() else { return }; + let wb = &d.wb; + let mut clicked = None; + for name in RIBBON_TABLE_STYLES { + let (r, resp) = ui.allocate_exact_size(vec2(52.0, 40.0), Sense::click()); + paint_table_swatch(ui, r, wb, name); + if name == current { + ui.painter().rect_stroke(r.expand(2.5), 2.0, Stroke::new(2.0, t.accent), StrokeKind::Outside); + } + if resp.hovered() { + ui.painter().rect_stroke(r.expand(1.0), 2.0, Stroke::new(2.0, Color32::from_rgb(0xE8, 0x7D, 0x2B)), StrokeKind::Outside); + } + if resp.on_hover_text(name).clicked() { + clicked = Some(name); + } } + clicked + }; + if let Some(name) = clicked { + act(app, "table.style", json!({"table": tname, "style": name})); } let more = icon_button(ui, Icon::Chevron, t.text_dim, "More Table Styles", vec2(18.0, 40.0)); anchor_keytip(app, ui, &more, &["table.style"]);