Address CodeRabbit review: borrow the workbook and keep both swatch outlines (#2148)

This commit is contained in:
Francisco Herrera
2026-10-21 15:16:30 -05:00
parent a9223eabf8
commit c3184b74f9
+21 -13
View File
@@ -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"]);